<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="Button" />
</LinearLayout>
常用属性:
orientation: 用于指定布局的排列方式(竖直还是水平);
gravity: 用于指定子类控件在布局中的位置,可选的值如下
多个值中间可以用 '|' 符号隔开;
注意这里的gravity 要和子类控件的layout_gravity 区分。这里的gravity 是指控件在当前布局中的位置,而子类控件的layout_gravity 用于指定子类控件在父类容器中的位置。父类的gravity 的“优先级”更高。如果LinearLayout 的排列方式为horizontal, gravity 仍然可以指定水平方向的属性,如center_horizontal; 而子类的layout_gravity 无法指定水平方向上的属性,因为水平方向上的长度是不确定的。