Android布局之RelativeLayout相對布局
RelativeLayout是相對布局控件:以控件之間相對位置或相對父容器位置進(jìn)行排列。
相對布局常用屬性:
子類控件相對子類控件:值是另外一個控件的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----對齊到控件基準(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相對布局相關(guān)知識,希望大家喜歡。
相關(guān)文章
Android 輕松實(shí)現(xiàn)圖片倒影效果實(shí)例代碼
這篇文章主要介紹了Android 輕松實(shí)現(xiàn)圖片倒影效果實(shí)例代碼,有需要的朋友可以參考一下2014-01-01Android編程之創(chuàng)建自己的內(nèi)容提供器實(shí)現(xiàn)方法
這篇文章主要介紹了Android編程之創(chuàng)建自己的內(nèi)容提供器實(shí)現(xiàn)方法,結(jié)合具體實(shí)例形式分析了Android創(chuàng)建內(nèi)容提供器的原理、步驟與相關(guān)操作技巧,需要的朋友可以參考下2017-08-08Android實(shí)現(xiàn)手勢滑動多點(diǎn)觸摸縮放平移圖片效果(二)
這篇文章主要介紹了Android實(shí)現(xiàn)手勢滑動多點(diǎn)觸摸縮放平移圖片效果,實(shí)現(xiàn)圖片支持多點(diǎn)觸控,自由的進(jìn)行縮放、平移的注意事項(xiàng),感興趣的小伙伴們可以參考一下2016-02-02Android RadioGroup多行顯示效果 解決單選問題
這篇文章主要為大家詳細(xì)介紹了Android RadioGroup多行顯示效果,解決單選問題,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-11-11Android開發(fā)EditText實(shí)現(xiàn)密碼顯示隱藏
這篇文章主要為大家詳細(xì)介紹了Android開發(fā)EditText實(shí)現(xiàn)密碼顯示隱藏,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-08-08Android ListView實(shí)現(xiàn)單選及多選等功能示例
這篇文章主要介紹了Android ListView實(shí)現(xiàn)單選及多選等功能的方法,結(jié)合實(shí)例形式分析了ListView單選、多選及長按多選等功能相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-08-08Android中基于XMPP協(xié)議實(shí)現(xiàn)IM聊天程序與多人聊天室
這篇文章主要介紹了Android中基于XMPP協(xié)議實(shí)現(xiàn)IM聊天程序與多人聊天室的方法,XMPP基于XML數(shù)據(jù)格式傳輸,一般用于即時消息(IM)以及在線現(xiàn)場探測,需要的朋友可以參考下2016-02-02