1.线性布局
①android:layout_weight权重的描述:
layout_weight 用于给一个线性布局中的诸多视图的重要度赋值。 所有的视图都有一个layout_weight值,默认为零,意思是需要显示多大的视图就占据多大的屏幕空 间。若赋一个高于零的值,则将父视 图中的可用空间分割,分割大小具体取决于每一个视图的layout_weight 。
②android:layout_gravity设置对齐方式
以上两种属性是线性布局中最重要的属性,使用线性布局可是设置出所有的图形格式,但是布局嵌套布局不建议使用。
2.框架布局
框架布局是最简单的布局方式、所有添加到这个布局中的视图都是以层叠的方式显示。第一个添加到框架布局中的视图显示在最底层,最后一个被放在最顶层,上一层的视图会覆盖下一层的视图,因此框架布局类似堆栈布局。
当要做图片的重叠显示的时候可以选择框架布局。
3.相对布局
RelativeLayout可以设置某一个视图相对于其他视图的位置,这些位置可以包括上下左右等。
以上的属性可以相互配合使用实现左上,右上,左下,右下的显示视图。实现代码如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:gravity="center" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button2" android:textSize="16dp"></Button> <Button android:layout_width="wrap_content" android:id="@+id/button2" android:layout_height="wrap_content" android:text="Button" android:textSize="16dp" android:layout_toRightOf="@id/button1" android:layout_below="@id/button1"></Button> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button2" android:textSize="16dp" android:layout_toLeftOf="@id/button2" android:layout_below="@id/button2"></Button> <Button android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button3" android:textSize="16dp" android:layout_toRightOf="@id/button2" android:layout_above="@id/button2"></Button> <Button android:id="@+id/button5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button4" android:textSize="16dp" android:layout_toRightOf="@id/button2" android:layout_below="@id/button2"></Button> </RelativeLayout>