Android布局之RelativeLayout相對(duì)布局
RelativeLayout是相對(duì)布局控件:以控件之間相對(duì)位置或相對(duì)父容器位置進(jìn)行排列。
相對(duì)布局常用屬性:
子類控件相對(duì)子類控件:值是另外一個(gè)控件的id
android:layout_above----------位于給定DI控件之上
android:layout_below ----------位于給定DI控件之下
android:layout_toLeftOf -------位于給定控件左邊
android:layout_toRightOf ------位于給定控件右邊
android:layout_alignLeft -------左邊與給定ID控件的左邊對(duì)齊
android:layout_alignRight ------右邊與給定ID控件的右邊對(duì)齊
android:layout_alignTop -------上邊與給定ID控件的上邊對(duì)齊
android:layout_alignBottom ----底邊與給定ID控件的底邊對(duì)齊
android:layout_alignBaseline----對(duì)齊到控件基準(zhǔn)線
學(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相對(duì)布局相關(guān)知識(shí),希望大家喜歡。
相關(guān)文章
詳解Android如何設(shè)計(jì)一個(gè)全局可調(diào)用的ViewModel對(duì)象
很多時(shí)候我們需要維護(hù)一個(gè)全局可用的ViewModel,因?yàn)檫@樣可以維護(hù)全局同一份數(shù)據(jù)源,且方便使用協(xié)程綁定App的生命周期,那如何設(shè)計(jì)全局可用的ViewModel對(duì)象,文中介紹的非常詳細(xì),需要的朋友可以參考下2023-05-05
Android仿新浪微博oauth2.0授權(quán)界面實(shí)現(xiàn)代碼(2)
這篇文章主要為大家詳細(xì)介紹了Android仿新浪微博oauth2.0授權(quán)界面實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-11-11
Android編程自定義title bar(標(biāo)題欄)示例
這篇文章主要介紹了Android編程自定義title bar(標(biāo)題欄)的方法,結(jié)合實(shí)例形式分析了Android針對(duì)標(biāo)題欄的設(shè)置與頁(yè)面布局操作相關(guān)技巧,需要的朋友可以參考下2016-10-10
Android代碼實(shí)現(xiàn)AdapterViews和RecyclerView無(wú)限滾動(dòng)
這篇文章主要為大家詳細(xì)介紹了Android代碼實(shí)現(xiàn)AdapterViews和RecyclerView無(wú)限滾動(dòng)的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-07-07
RecycleView實(shí)現(xiàn)item側(cè)滑刪除與拖拽
這篇文章主要為大家詳細(xì)介紹了RecycleView實(shí)現(xiàn)item側(cè)滑刪除與拖拽,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-11-11
Android 實(shí)現(xiàn)滑動(dòng)方法總結(jié)
這篇文章主要介紹了Android 實(shí)現(xiàn)滑動(dòng)方法總結(jié)的相關(guān)資料,需要的朋友可以參考下2017-07-07
Android Webview上的ssl warning的處理方式詳解及實(shí)例
這篇文章主要介紹了Android Webview上的ssl warning的處理方式詳解及實(shí)例的相關(guān)資料,需要的朋友可以參考下2017-02-02

