相对布局(中)
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 <TextView 16 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 <TextView 12 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. 對齊至父控件的中央
? ? ?? ????
?
轉載于:https://www.cnblogs.com/iMirror/p/3810264.html
總結
- 上一篇: 四、记一次失败的 CAS 搭建 之 结果
- 下一篇: view里文书删除时报错的解决案