Android 5种常用布局的常用属性
一.LinearLayout 线性布局
android:orientation="vertical" 设置线性布局方向,表示竖直方式对齐
android:layout_width="fill_parent" 定义当前视图在屏幕上 可以消费的宽度
android:layout_heigh="wrap_content" 定义当前视图在屏幕上 可以消费的高度
android:gravity 对齐方式.对元素本身说的,元素本身的文本显示在什么地方靠着换个属性设置,不过不设置默认是在左侧的
android:layout_weight 所有的视图都有一个layout_weight值,默认为零,意思是需要显示多大的视图就占据多大的屏幕空间
二.AbsoluteLayout绝对布局
三.FrameLayout框架布局
四.RelativeLayout相对布局
(1)定位与组件的上下左右
android:layout_below="@id/.."
android:layout_above="@id/"
android:layout_toLeftOf="@id/"
android:layout_toRightOf="@id/"
(2)定位与组件的边缘对齐
android:layout_alignLeft="@id/"
android:layout_alignRight="@id/"
android:layout_alignTop="@id/"
android:layout_alignBottom="@id/"
(3)定位与父组件的边缘对齐
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
(4)与整个屏幕的关系
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_centerInParent="true"
(5)组件间的距离
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:layout_margin="5dp"
五.TableLayout表格布局
类似于Swing中的GridLayout;
表格布局的每行用<TabRow>括起来;
在<TableLayout>中可以定义如下属性:
(1)android:shrinkColumns="1" 表明第2个控件如果里面的内容过多,会收缩,扩展到第二行,而不是延伸;
(2)android:stretchColumns="2" 如果有空白,第3个控件填充;
(3)android:collapseColumns="0" 隐藏指定的列
在控件中设置:
(1)android:layout_column="2" 将此控件放在第3个位置;
(2)android:layout_span="2" 此控件占据2个单元位置;
水平线
<view
android:layout_height="2dp"
android:backgroup="#FF9090"/>