今天調佈局的時候 想把界面作成橫屏豎屏均可以的 忽然發現以前理解的android:佈局參數都是有問題的 今天貼出來 下次本身也記得android
如下大部爲用在RelativeLayout中的一些參數:
android:layout_above 將該控件的底部至於給定ID的控件之上,但不會左對齊,默認置於父窗口最左邊,會覆蓋最左邊的控件
android:layout_below 將該控件的頂部至於給定ID的控件之下,但不會左對齊,默認置於父窗口最左邊,會覆蓋最左邊的控件
android:layout_toLeftOf 將該控件的右邊緣和給定ID的控件的左邊緣對齊,默認置於父窗口最上面,會覆蓋最上面的控件
android:layout_toRightOf 將該控件的左邊緣和給定ID的控件的右邊緣對齊,默認置於父窗口最上面,會覆蓋最上面的控件佈局
android:alignParentBottom 若是該值爲true,則將該控件的底部和父控件的底部對齊,默認置於父窗口最左下,會覆蓋最左下的控件
android:layout_alignParentLeft 若是該值爲true,則將該控件的左邊與父控件的左邊對齊,默認置於父窗口最左上,會覆蓋最左上的控件
android:layout_alignParentRight 若是該值爲true,則將該控件的右邊與父控件的右邊對齊,默認置於父窗口最右上,會覆蓋最右上的控件
android:layout_alignParentTop 若是該值爲true,則將控件的頂部與父控件的頂部對齊,默認置於父窗口最左上,會覆蓋最左上的控件spa
android:layout_alignBaseline該控件的baseline和給定ID的控件的baseline對齊,並置於父窗口最左邊,會覆蓋最左邊的控件
android:layout_alignBottom 將該控件的底部邊緣與給定ID控件的底部邊緣對齊,並置於父窗口最左邊,會覆蓋最左邊的控件
android:layout_alignLeft 將該控件的左邊緣與給定ID控件的左邊緣對齊,並置於父窗口最上邊,會覆蓋最上邊的控件
android:layout_alignRight 將該控件的右邊緣與給定ID控件的右邊緣對齊,並置於父窗口最上邊,會覆蓋最上邊的控件
android:layout_alignTop 將給定控件的頂部邊緣與給定ID控件的頂部對齊,並置於父窗口最左邊,會覆蓋最左邊的控件.net
原文:http://my.oschina.net/honeyming/blog/130761code
實例1介紹: -- 未加入對齊方式xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.relativelayoutdemo.MainActivity" > <TextView android:id="@+id/tv1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="@string/hello_world" /> <TextView android:id="@+id/tv2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/tv1" android:text="@string/hello_world" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/tv1" android:text="@string/hello_world" /> </RelativeLayout>
效果:blog
實例2介紹: -- 加入對齊方式 。在tv1下面的對齊方式是左邊界對齊。在tv1右邊的對齊方式是上邊界對齊。get
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.relativelayoutdemo.MainActivity" > <TextView android:id="@+id/tv1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="@string/hello_world" /> <TextView android:id="@+id/tv2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/tv1" android:layout_alignLeft="@id/tv1" android:text="@string/hello_world" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/tv1" android:layout_alignTop="@id/tv1" android:text="@string/hello_world" /> </RelativeLayout>
結果:string