可以设置控件与父控件的位置,控件与控件之间的位置。
1. 控件与父容器位置属性
android:layout_alignParentLeft="true" 子控件相对于父容器靠左边
android:layout_alignParentTop="true" 子控件相对于父容器靠 上边
android:layout_marginTop="50dp" 子控件与父容器上边距距离
android:layout_marginBottom="50dp" 子控件与父容器下边距距离
android:layout_marginRight="50dp" 子控件与父容器右边距距离
android:layout_marginLeft="50dp" 子控件与父容器左边距距离
android:layout_centerInParent="true"//子控件在父容器中居中显示
android:layout_centerHorizontal="true" //子控件在父容器中水平居中
android:layout_centerVertical="true" 子控件在父容器中垂直居中
下面的示例展示下相对于父容器的布局
2.控件与控件间位置属性
控件与控件之间的位置属性,是指控件与相邻控件的位置设置,主要有以下属性
android:layout_below="@+id/textView1" 该控件位于指定控件的下方
android:layout_toLeftOf="@+id/textView1" 控件位于指定控件的左侧
android:layout_toRightOf="@+id/textView1" 控件位于指定控件的右侧
android:layout_above="@+id/textView1" 控件位于指定控件的上面
android:layout_alignBaseline="" 该控件的内容与指定控件的内容在同一直线上
android:layout_alignBottom=""该控件的底部与指定控件的底部对齐
android:layout_alignLeft="" 该控件与指定控件左侧对齐
android:layout_alignRight="" 该控件与指定控件右侧对齐
android:layout_alignTop="" 该控件与指定控件的顶部对齐
3.商品列表示例