標籤:android開發 布局 relativelayout 移動端開發 遊響雲停工作室
相對布局RelativeLayout是Android布局中一個比較常用的控制項,使用該控制項可以布局出適合各種螢幕解析度的布局,RelativeLayout採用相對位置進行控制項屬性設定.
可以設定控制項與父控制項的位置,控制項與控制項之間的位置。
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" 子控制項在父容器中垂直置中
下面的樣本展示下相對於父容器的布局
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/textView1" android:layout_width="match_parent" android:layout_height="match_parent" android:text="相對父容易布局" android:background="#97FFFF" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginTop="50dp" android:layout_marginBottom="50dp" android:layout_marginRight="50dp" /></RelativeLayout>
2.控制項與控制項間位置屬性
3.商品列表示例
.Net程式員玩轉Android開發---(7)相對布局RelativeLayout