zoukankan      html  css  js  c++  java
  • Andriod布局之LinearLayout

      LinearLayout是安卓中的常见布局,即线性布局。(提示:在Andriod中要常用alt+/快捷键来补全代码

      其中有一个重要的属性android:orientation,它是表示线性布局的方向问题。

      常见的这种布局案例有,计算器界面布局,下面就粘上代码: 

     

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"  //引用包
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"  //垂直方向
    tools:context=".MainActivity"
    >

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"  //权重,在容器中的占比
    android:orientation="vertical" >

    <EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="right"  //文字显示方向
    />
    </LinearLayout>

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_weight="1"
    android:orientation="horizontal"
    >
    <Button
    android:text="7"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="15sp"
    android:layout_weight="1"
    />
    <Button
    android:text="8"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="15sp"
    android:layout_weight="1"
    />
    <Button
    android:text="9"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    />
    <Button
    android:text="/"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    />
    </LinearLayout>

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_weight="1"
    android:orientation="horizontal"
    >
    <Button
    android:text="4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="15sp"
    android:layout_weight="1"
    />
    <Button
    android:text="5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="15sp"
    android:layout_weight="1"
    />
    <Button
    android:text="6"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    />
    <Button
    android:text="*"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    />
    </LinearLayout>
    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_weight="1"
    android:orientation="horizontal"
    >
    <Button
    android:text="1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="15sp"
    android:layout_weight="1"
    />
    <Button
    android:text="2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="15sp"
    android:layout_weight="1"
    />
    <Button
    android:text="3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    />
    <Button
    android:text="+"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    />
    </LinearLayout>
    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_weight="1"
    android:orientation="horizontal"
    >
    <Button
    android:text="cl"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="15sp"
    android:layout_weight="1"
    />
    <Button
    android:text="."
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="15sp"
    android:layout_weight="1"
    />
    <Button
    android:text="="
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    />
    <Button
    android:text="-"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    />
    </LinearLayout>
    </LinearLayout>

      效果图:如下

  • 相关阅读:
    ACE 资源
    为什么在VC6中TRACE不能输出信息?
    实例源码Android智能家居系统
    项目源码Android音乐播放器
    实例源码Android捕鱼达人经典游戏
    精品教程NDK环境搭建(1)CYGWIN的安装
    实例源码Android人脸识别技术(眼睛位置)
    精品教程NDK基础例子,编译.SO文件
    项目源码Android高清壁纸应用
    精品教程Android中通过NDK使用OpenCV库
  • 原文地址:https://www.cnblogs.com/peterpc/p/4181360.html
Copyright © 2011-2022 走看看