android Activity相對(duì)布局的使用方法
相對(duì)布局要比前面講的線性布局和表格布局要靈活一些,所以平常用得也是比較多的。相對(duì)布局控件的位置是與其周?chē)丶奈恢孟嚓P(guān)的,從名字可以看出來(lái),這些位置都是相對(duì)的,確定出了其中一個(gè)控件的位置就可以確定另一個(gè)控件的位置了。
本次實(shí)驗(yàn)就是顯示如下的activity:
其中只有2個(gè)button,1個(gè)textview,1個(gè)edittext。
在相對(duì)布局中,一般用到的控件屬性解釋如下:
在相對(duì)布局中有如下屬性,解釋如下:
android:layout_above 為將該控件的底部放在指定id控件的上方
android:layout_below 同理類(lèi)似,將該控件的頂部放在指定id控件的下方
android:layout_toLeftOf 將該控件的右端緊挨著放在指定id控件的左端。
android:layout_toRightOf 將該控件的左端緊挨著放在指定id控件的右端
android:layout_alignParentRight 為true時(shí)將該控件右端與父控件右端對(duì)齊
android:layout_alignParentLeft 為true時(shí)將該控件左端與父控件左端對(duì)齊
android:layout_alignParentTop 為true時(shí)將該控件頂端與父控件頂端對(duì)齊
android:layout_alignParentBottom 為true時(shí)將該控件底端與父控件底端對(duì)齊
android:layout_alignBottom 將該控件底部與指定id控件底部控件對(duì)齊
android:layout_alignLeft 將該控件左邊與指定id控件左邊對(duì)齊
android:layout_alignRight 將該控件右邊與指定id控件右邊對(duì)齊
android:layout_alignTop 將該控件頂端與指定id控件頂端對(duì)齊
實(shí)現(xiàn)上面activity比較簡(jiǎn)單,其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:padding="10px" >
<TextView
android:id="@+id/input"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/input_dis"
tools:context=".MainActivity" />
<EditText
android:id="@+id/edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/input"
android:background="@android:drawable/editbox_background"
/>
<Button
android:id="@+id/ok"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="@id/edit"
android:layout_alignParentRight="true"
android:layout_marginLeft="10px"
android:text="@string/ok"
/>
<Button
android:id="@+id/cancel"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="@id/edit"
android:layout_toLeftOf="@id/ok"
android:text="@string/cancel"
/>
</RelativeLayout>
總結(jié):activity的相對(duì)布局比較靈活,一些常見(jiàn)的屬性也比較多,用得多自然就會(huì)了。
作者:tornadomeet
- Android自定義View實(shí)現(xiàn)垂直時(shí)間軸布局
- android layout 按比例布局的代碼
- Android中RecyclerView布局代替GridView實(shí)現(xiàn)類(lèi)似支付寶的界面
- android動(dòng)態(tài)加載布局文件示例
- Android實(shí)現(xiàn)輸入法彈出時(shí)把布局頂上去和登錄按鈕頂上去的解決方法
- Android TabLayout(選項(xiàng)卡布局)簡(jiǎn)單用法實(shí)例分析
- Android布局——Preference自定義layout的方法
- Android應(yīng)用借助LinearLayout實(shí)現(xiàn)垂直水平居中布局
- android LinearLayout和RelativeLayout組合實(shí)現(xiàn)精確布局方法介紹
- Android實(shí)現(xiàn)Z軸布局效果
相關(guān)文章
通知監(jiān)控NotificationListenerService onNotificationPosted重復(fù)回
這篇文章主要為大家介紹了通知監(jiān)控NotificationListenerService onNotificationPosted重復(fù)回調(diào)問(wèn)題解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02
Android BroadcastReceiver廣播機(jī)制概述
這篇文章主要為大家詳細(xì)介紹了Android BroadcastReceiver廣播機(jī)制,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-08-08
Android使用第三方庫(kù)實(shí)現(xiàn)日期選擇器
這篇文章主要為大家詳細(xì)介紹了Android使用第三方庫(kù)實(shí)現(xiàn)日期選擇器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-10-10
Android中比較兩個(gè)圖片是否一致的問(wèn)題
這篇文章主要介紹了Android中比較兩個(gè)圖片是否一致的問(wèn)題,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-10-10
Android SDK 百度地圖通過(guò)poi城市內(nèi)檢索簡(jiǎn)介接口的使用
這篇文章主要介紹了Android SDK 百度地圖通過(guò)poi城市內(nèi)檢索簡(jiǎn)介接口的使用的相關(guān)資料,需要的朋友可以參考下2016-02-02
Ionic2創(chuàng)建App啟動(dòng)頁(yè)左右滑動(dòng)歡迎界面
使用Ionic2創(chuàng)建應(yīng)用非常簡(jiǎn)單,只需在V1的命令后跟上--v2即可.這篇文章主要介紹了Ionic2創(chuàng)建App啟動(dòng)頁(yè)左右滑動(dòng)歡迎界面的相關(guān)資料,需要的朋友可以參考下2016-10-10
android開(kāi)發(fā)教程之使用listview顯示qq聯(lián)系人列表
這篇文章主要介紹了android使用listview顯示qq聯(lián)系人列表的示例,需要的朋友可以參考下2014-02-02

