淺析Android App的相對布局RelativeLayout
一、什么是相對布局
相對布局是另外一種控件擺放的方式
相對布局是通過指定當(dāng)前控件與兄弟控件或者父控件之間的相對位置,從而達(dá)到相對的位置
二、為什么要使用相對布局
相對于線性布局ui性能好
三、相對布局的兩組常用屬性
值為某個存在控件id:
(1)android:layout_below放在某個存在id控件的下邊緣(也就是當(dāng)前控件的上邊對齊到某個id控件的下邊緣
(2)android:layout_above放在某個存在id控件的上邊緣(也就是當(dāng)前控件的下邊緣對齊到某個id控件的上邊緣
(3)android:layout_toLeftOf 放在某個存在id控件的左邊(也就是當(dāng)前控件的右邊對齊到某個id控件的左邊
(4)android:layout_toRightOf 放在某個存在id控件的右邊(也就是當(dāng)前控件的左邊對齊到某個id控件的右邊)
(5)android:layout_alignLeft 當(dāng)前的控件左邊緣對齊到某個存在的id控件的左邊緣
(6)android:layout_alignRigth 當(dāng)前的控件右邊緣對齊到某個存在的id控件的右邊緣
(7)android:layout_alignTop 當(dāng)前的控件上邊緣對齊到某個存在的id控件的上邊緣
(8)android:alignBottom 當(dāng)前的控件下邊緣對齊到某個存在的id控件的下邊緣
1.對齊至控件的基準(zhǔn)線
基準(zhǔn)線是為了保證印刷字母的整齊而劃定的線
值為某個存在控件的id:
android:layout_alignBaseline
2.與父控件的四個邊緣對齊
值為true or false:
(1)android:layout_aliginParentLeft 對齊到父控件的左邊
(2)android:layout_alignParentRight 對錢對齊到父控件的右邊
(3)android:layout_alignParentTop對齊到父控件的上邊
(4)android:layout_alignParentBottom 對齊到父控件的下邊
3.對齊至父控件的中央位置
值為 true or false:
(1)android:layout_centerInParent 對齊到父控件的最中央位置
(2)android:layout_layout_Horizontal 對齊到父控件水平方向中央的位置
(3)android:layout_centerVertical 對齊到父控件垂直方向中央的位置
4.android 4.2 Relativelayout布局的新屬性
值為某個存在控件的di:
(1)android:layout_alignStart 當(dāng)前控件的起始位置對對齊到某個存在控件id的起始位置
(2)android:layout_alignEnd 當(dāng)前控件的起始位置對對齊到某個存在控件id的對齊到終點位置
值為true or false:
(1)android:layout_alignParentStart 對齊到父控件的起始位置
(2)android:layout_alignParentEnd 對齊到父控件的終點位置
5.字體居中
android:gravity="center"
android:hint="值"
andriod:inputType="textpassworld"
四、相對布局實例—登錄界面
<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:layout_margin="20dp" tools:context=".MainActivity" > <TextView android:id="@+id/Txttitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:gravity="center_horizontal" android:layout_alignParentRight="true" android:text="登錄界面"/> <EditText android:id="@+id/username" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@id/Txttitle" android:layout_alignRight="@id/Txttitle" android:layout_below="@id/Txttitle" android:layout_marginTop="20dp" android:hint="username"/> <EditText android:id="@+id/password" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/username" android:layout_alignLeft="@id/username" android:layout_alignRight="@id/username" android:layout_marginTop="20dp" android:hint="password" android:inputType="textCapWords"/> </RelativeLayout>
相關(guān)文章
Android使用Gallery實現(xiàn)照片拖動的特效
這篇文章主要介紹了Android如何使用Gallery實現(xiàn)照片拖動的特效,幫助大家更好的理解和利用Android進(jìn)行開發(fā),感興趣的朋友可以了解下2021-01-01android中可以通過兩種方式調(diào)用接口發(fā)送短信
調(diào)用系統(tǒng)短信接口直接發(fā)送短信;調(diào)起系統(tǒng)發(fā)短信功能,本文將給出兩種方式的實現(xiàn)代碼,感興趣的朋友可以了解下,或許對你有所幫助2013-02-02Android?ScrollView實現(xiàn)滾動超過邊界松手回彈
這篇文章主要為大家詳細(xì)介紹了Android?ScrollView實現(xiàn)滾動超過邊界松手回彈,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-04-04Android WebView如何判定網(wǎng)頁加載的錯誤
這篇文章主要介紹了Android WebView如何判定網(wǎng)頁加載的錯誤,幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下2021-04-04Android用 Mob 實現(xiàn)發(fā)送短信驗證碼實例
這篇文章主要介紹了Android用 Mob 實現(xiàn)發(fā)送短信驗證碼實例,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-06-06Android應(yīng)用內(nèi)懸浮窗的實現(xiàn)方案示例
本篇文章主要介紹了Android應(yīng)用內(nèi)懸浮窗的實現(xiàn)方案示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-08-08