一、LinearLayout布局控件xml属性Android:baselineAligned:是否允许用户调整它内容的基线。android:baselineAlignedChildIndex:当一个线性布局与另一个布局是按基线对齐的一部分,它可以指定其内容的基线对齐方式。android:gravity:指定控件中内容的基本内容。android:orientation:设置它内容的对其方向,有两个可以选择的值:horizontal和vertical。分别表示水平排列和垂直排列。LinearLayout是线性布局控件,它包含的子控件将以横向或竖向的方式排列,按照相对位置来排列所有的widgets或者其他的containers,超过边界时,某些控件将缺失或消失,不能完全显示。因此垂直方式排列时,每一行只会有一个widget或者是container,而不管他们有多宽,而水平方式排列是将会只有一个行高(高度为最高子控件的高度加上边框高度)。LinearLayout保持其所包含的widget或者是container之间的间隔以及互相对齐(相对一个控件的右对齐、中间对齐或者左对齐)。LinearLayout还支持为其包含的widget或者是container指定填充权值。允许其包含的widget或者是container可以填充屏幕上的剩余空间。剩余的空间会按这些widgets或者是containers指定的权值比例分配屏幕。默认的 weight 值为0,表示按照widgets或者是containers实际大小来显示,若高于0的值,则将Container剩余可用空间分割,分割大小具体取决于每一个widget或者是container的layout_weight及该权值在所有widgets或者是containers中的比例。例如,如果有三个文本框,前两个文本框的取值一个为2,一个为1,显示第三个文本框后剩余的空间的2/3给权值为2的,1/3大小给权值为1的。而第三个文本框不会放大,按实际大小来显示。也就是权值越大,重要度越大,显示时所占的剩余空间越大。LinearLayout示例: 布局文件:
- <?xml version="1.0" encoding="utf-8"?>
-
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-
- android:orientation="horizontal"
-
- android:layout_width="fill_parent"
-
- android:layout_height="fill_parent"
-
- >
-
- <!--
-
- android:id ———————————— 为控件指定id
-
- android:text —————————— 指定控件当中显示的文字
-
- android:gravity ——————— 指定控件中内容的基本位置,比如居中,靠右等位置
-
- android:textSize —————— 指定控件当中字体的大小
-
- android:background ———— 指定该控件所使用的背景色,RGB命名法
-
- android:width ————————— 指定控件的宽度
-
- android:height ———————— 指定控件的高度
-
- android:padding ——————— 指定控件的四个方向的内边距
-
- android:paddingLeft———— 指定控件的左内边距
-
- android:paddingRight——— 指定控件的右内边距
-
- android:paddingTop ———— 指定控件的上内边距
-
- android:paddingBottom — 指定控件的底内边距
-
- android:sigleLine ————— 如果设置为真的话,则将控件中的内容在一行进行显示
-
- android:layout_weight — 设置在LinearLayout控件中的填充权值
-
- -->
-
- <TextView
-
- android:id="@+id/first"
-
- android:layout_width="200dip"
-
- android:layout_height="200dip"
-
- android:text="第一个TextView"
-
- android:textSize="20pt"
-
- android:gravity="center_vertical"
-
- android:background="#aa0000"
-
- android:paddingLeft="10dip"
-
- android:paddingRight="30dip"
-
- android:paddingTop="10dip"
-
- android:paddingBottom="30dip"
-
- android:layout_weight="2"
-
- />
-
- <TextView
-
- android:id="@+id/second"
-
- android:layout_width="200dip"
-
- android:layout_height="200dip"
-
- android:text="第二个TextView"
-
- android:textSize="20pt"
-
- android:gravity="center_vertical"
-
- android:background="#0000aa"
-
- android:paddingLeft="10dip"
-
- android:paddingRight="30dip"
-
- android:paddingTop="10dip"
-
- android:paddingBottom="30dip"
-
- android:layout_weight="1"
-
- />
-
- </LinearLayout>
显示效果: