1.线性布局(LinearLayout)
按照垂直或者水平方向布局组件,其中的控件可以通过weight
属性来平分剩余空间(注意是平分剩余空间,不是平分所有空间),比如:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello"
android:id="@+id/abc"
android:background="#00ff00"
android:layout_weight="1" /> //这个和下面那个按1:1平分剩余空间
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hi"
android:id="@+id/cde"
android:background="#ffff00"
android:layout_weight="1" />
</LinearLayout>
这个时候就会发现第一个标签会比第二个长一点点,因为hello比hi长一点,而剩余平分的一样,加起来第一个标签就更长一些了,但如果是想他们都占所有的一半,那也可以,只要把android:layout_width="wrap_content"
里的值改成0dp
就行了
2.帧布局(FrameLayout )
组件从屏幕的左上角坐标布局组件
3.表格布局(TabIeLayout)
按照行列方式布局组件
4.相对布局(RelativeLayout)
相对其他组件的布局方式
5.绝对布局(AbsoluteLayout )
按照绝对坐标来布局组件