Android布局之RelativeLayout相對布局
RelativeLayout是相對布局控件:以控件之間相對位置或相對父容器位置進行排列。
相對布局常用屬性:
子類控件相對子類控件:值是另外一個控件的id
android:layout_above----------位于給定DI控件之上
android:layout_below ----------位于給定DI控件之下
android:layout_toLeftOf -------位于給定控件左邊
android:layout_toRightOf ------位于給定控件右邊
android:layout_alignLeft -------左邊與給定ID控件的左邊對齊
android:layout_alignRight ------右邊與給定ID控件的右邊對齊
android:layout_alignTop -------上邊與給定ID控件的上邊對齊
android:layout_alignBottom ----底邊與給定ID控件的底邊對齊
android:layout_alignBaseline----對齊到控件基準線
學(xué)習(xí)導(dǎo)圖如下所示:

注:父容器定位的屬性值只能是Boolean ,兄弟組件定位的屬性值只能是ID
典型案例(梅花)
<?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">
<ImageView
android:id="@+id/img1"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_centerInParent="true"
android:src="@mipmap/ic_launcher"/>
<ImageView
android:id="@+id/img2"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_above="@id/img1"
android:layout_centerHorizontal="true"
android:src="@mipmap/ic_launcher"/>
<ImageView
android:id="@+id/img3"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_below="@id/img1"
android:layout_centerHorizontal="true"
android:src="@mipmap/ic_launcher"/>
<ImageView
android:id="@+id/img4"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_toLeftOf="@id/img1"
android:layout_centerVertical="true"
android:src="@mipmap/ic_launcher"/>
<ImageView
android:id="@+id/img5"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_toRightOf="@id/img1"
android:layout_centerVertical="true"
android:src="@mipmap/ic_launcher"/>
</RelativeLayout>
以上內(nèi)容是小編給大家介紹的Android布局之RelativeLayout相對布局相關(guān)知識,希望大家喜歡。
相關(guān)文章
詳解Android如何設(shè)計一個全局可調(diào)用的ViewModel對象
很多時候我們需要維護一個全局可用的ViewModel,因為這樣可以維護全局同一份數(shù)據(jù)源,且方便使用協(xié)程綁定App的生命周期,那如何設(shè)計全局可用的ViewModel對象,文中介紹的非常詳細,需要的朋友可以參考下2023-05-05
Android仿新浪微博oauth2.0授權(quán)界面實現(xiàn)代碼(2)
這篇文章主要為大家詳細介紹了Android仿新浪微博oauth2.0授權(quán)界面實現(xiàn)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-11-11
Android代碼實現(xiàn)AdapterViews和RecyclerView無限滾動
這篇文章主要為大家詳細介紹了Android代碼實現(xiàn)AdapterViews和RecyclerView無限滾動的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-07-07
RecycleView實現(xiàn)item側(cè)滑刪除與拖拽
這篇文章主要為大家詳細介紹了RecycleView實現(xiàn)item側(cè)滑刪除與拖拽,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-11-11
Android Webview上的ssl warning的處理方式詳解及實例
這篇文章主要介紹了Android Webview上的ssl warning的處理方式詳解及實例的相關(guān)資料,需要的朋友可以參考下2017-02-02

