標籤:des android cWeb style class blog
1. 對齊至控制項的基準線
2. 與父控制項的四個邊緣對齊
3. 對齊至父控制項的中央
1. 對齊至控制項的基準線
1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 tools:context="first.pack.MainActivity$PlaceholderFragment" > 6 7 <TextView 8 android:id="@+id/firstView" 9 android:layout_width="wrap_content"10 android:layout_height="wrap_content"11 android:textSize="50sp"12 android:background="#FF0000"13 android:text="hello" />14 15 <TextView16 android:layout_width="wrap_content"17 android:layout_height="wrap_content"18 android:layout_toRightOf="@+id/firstView"19 android:layout_alignBaseline="@+id/firstView" //對齊基準線!!!20 android:background="#00FF00"21 android:text="mirrorhanyu" />22 23 </RelativeLayout>
2. 與父控制項的四個邊緣對齊
1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 tools:context="first.pack.MainActivity$PlaceholderFragment" > 6 7 <TextView 8 android:id="@+id/firstView" 9 android:layout_width="wrap_content"10 android:layout_height="wrap_content"11 android:textSize="50sp"12 android:background="#FF0000"13 android:layout_alignParentRight="true" //與父控制項右邊對齊14 android:text="hello" /> 15 16 </RelativeLayout>
當代碼為
1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 tools:context="first.pack.MainActivity$PlaceholderFragment" > 6 7 <RelativeLayout 8 android:layout_width="wrap_content" 9 android:layout_height="300dp"10 android:background="#00FF00">11 <TextView12 android:id="@+id/firstView"13 android:layout_width="wrap_content"14 android:layout_height="wrap_content"15 android:textSize="50sp"16 android:background="#FF0000"17 android:layout_alignParentRight="true" //與就近的父控制項對齊18 android:layout_alignParentBottom="true"19 android:text="hello" /> 20 </RelativeLayout>21 </RelativeLayout>
3. 對齊至父控制項的中央