Android應(yīng)用的LinearLayout中嵌套R(shí)elativeLayout的布局用法
想將Button和ListView分別放在屏幕的一左一右。
單純使用android:gravity和android:layout_gravity不成功。
于是涉及到RelativeLayout。
關(guān)鍵為:android:layout_alignParentRight="true",
android:layout_alignParentLeft="true":
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_vertical"> <TextView android:id="@+id/mTextView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="right" android:padding="10dp"> <TextView android:id="@+id/mTextView01" android:layout_alignParentLeft="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="范例一" /> <Button android:id="@+id/mButton01" android:layout_alignParentRight="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="發(fā)送" /> </RelativeLayout> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="right" android:padding="10dp"> <TextView android:id="@+id/mTextView02" android:layout_alignParentLeft="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="范例二" /> <Button android:id="@+id/mButton01" android:layout_alignParentRight="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="發(fā)送" /> </RelativeLayout> </LinearLayout>
效果為:
PS:另附我的項(xiàng)目布局的一點(diǎn)經(jīng)驗(yàn)
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginLeft="50px" android:layout_marginRight="50px" android:layout_marginBottom="15px" android:layout_gravity="center" android:gravity="center"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="性別" android:textSize="18sp" android:layout_weight="3"/> <RadioGroup android:id="@+id/radioGroup" android:contentDescription="性別" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_weight="1"> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/radioMale" android:text="男" android:checked="true" android:layout_marginRight="15px" android:textSize="18sp"> </RadioButton> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/radioFemale" android:text="女" android:textSize="18sp"> </RadioButton> </RadioGroup> </LinearLayout> </LinearLayout>
開始時(shí)RadioGroup的layout_width="wrap_content",怎么設(shè)置權(quán)都達(dá)不到想要的效果。要改成fill_parent
RadioButton的尺寸比TextView大 所以顯示時(shí)TextView在上方,設(shè)置LinearLayout中android:gravity="center">即可。
相關(guān)文章
Android Activity中使用Intent實(shí)現(xiàn)頁面跳轉(zhuǎn)與參數(shù)傳遞的方法
這篇文章主要介紹了Android Activity中使用Intent實(shí)現(xiàn)頁面跳轉(zhuǎn)與參數(shù)傳遞的方法,結(jié)合實(shí)例形式簡單分析了Android中的Activity交互操作相關(guān)技巧,需要的朋友可以參考下2016-07-07Android開發(fā)Compose集成高德地圖實(shí)例
這篇文章主要為大家介紹了Android開發(fā)Compose里使用高德地圖實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08Android 中WallpaperManager用法實(shí)例
這篇文章主要介紹了Android 中WallpaperManager用法實(shí)例的相關(guān)資料,希望通過本文能幫助到大家實(shí)現(xiàn)這樣的功能,需要的朋友可以參考下2017-09-09Android開發(fā)之自定義刮刮卡實(shí)現(xiàn)代碼
本篇文章主要介紹了Android開發(fā)之自定義刮刮卡實(shí)現(xiàn)代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-07-07Android實(shí)現(xiàn)Bitmap位圖旋轉(zhuǎn)效果
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)Bitmap位圖旋轉(zhuǎn)效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-04-04Android中CountDownTimer 實(shí)現(xiàn)倒計(jì)時(shí)功能
本篇文章主要介紹了Android中CountDownTimer 實(shí)現(xiàn)倒計(jì)時(shí)功能,CountDownTimer 是android 自帶的一個(gè)倒計(jì)時(shí)類,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05Flutter實(shí)現(xiàn)仿微信分享功能的示例代碼
Flutter 用來快速開發(fā) Android iOS平臺(tái)應(yīng)用,在Flutter 中,通過 fluwx或者fluwx_no_pay 插件可以實(shí)現(xiàn)微信分享功能,本文將具體介紹實(shí)現(xiàn)的示例代碼,需要的可以參考一下2022-01-01android換膚功能 如何動(dòng)態(tài)獲取控件中背景圖片的資源id?
這篇文章主要為大家詳細(xì)介紹了android換膚功能中如何動(dòng)態(tài)獲取控件中背景圖片的資源id? ,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-08-08