Android應(yīng)用借助LinearLayout實(shí)現(xiàn)垂直水平居中布局
首先說的是LinearLayout布局下的居中一般是這樣的:
(注意:android:layout_width="fill_parent" android:layout_height="fill_parent" 屬性中,若水平居中,至少在寬度上占全屏;若垂直居中,則在高度上占全屏)
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center|center_horizontal|center_vertical" > // 上面gravity屬性的參數(shù):center為居中,center_horizontal為水平居中,center_vertical為垂直居中 <Button android:id="@+id/Binding_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="關(guān)聯(lián)新賬戶" /> </LinearLayout>
要實(shí)現(xiàn)垂直水平居中,幾個(gè)基本參數(shù)值得注意:
1、android:orientation="vertical"表示該布局下的元素垂直排列;
2、android:layout_gravity="center_horizontal"表示該布局在父布局里水平居中,此時(shí)其父布局必須擁有android:orientation="vertical"屬性;
3、android:layout_gravity="center_vertical"表示該布局在父布局里垂直居中,此時(shí)其父布局必須應(yīng)設(shè)置成android:orientation="horizontal"屬性(默認(rèn)為該屬性),且其父布局的高度應(yīng)設(shè)置為android:layout_height="fill_parent"屬性;
4、android:gravity="center_horizontal"表示該布局下的元素水平居中;
線性布局垂直水平居中布局文件實(shí)例:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <LinearLayout android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_gravity="center_horizontal" > <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_gravity="center_vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" > <TextView android:layout_width="100dp" android:layout_height="wrap_content" android:gravity="right" android:text="用戶名" /> <EditText android:layout_width="300dp" android:layout_height="wrap_content" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" > <TextView android:layout_width="100dp" android:layout_height="wrap_content" android:gravity="right" android:text="Email" /> <EditText android:layout_width="300dp" android:layout_height="wrap_content" /> </LinearLayout> </LinearLayout> </LinearLayout> </LinearLayout>
- Android使用LinearLayout設(shè)置邊框
- android LinearLayout和RelativeLayout組合實(shí)現(xiàn)精確布局方法介紹
- Android LinearLayout實(shí)現(xiàn)自動(dòng)換行效果
- Android中LinearLayout布局的常用屬性總結(jié)
- Android自定義LinearLayout布局顯示不完整的解決方法
- Android App中使用LinearLayout進(jìn)行居中布局的實(shí)例講解
- Android App中的多個(gè)LinearLayout嵌套布局實(shí)例解析
- Android自定義控件LinearLayout實(shí)例講解
- Android?LinearLayout快速設(shè)置每個(gè)item間隔
相關(guān)文章
android中intent傳遞list或者對(duì)象的方法
這篇文章主要介紹了android中intent傳遞list或者對(duì)象的方法,分析羅列了常用的幾種方法,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-01-01Android ListView之EfficientAdapte的使用詳解
這篇文章主要介紹了Android ListView之EfficientAdapte的使用詳解的相關(guān)資料,這里介紹EfficientAdapter 的使用方法,需要的朋友可以參考下2017-08-08Android編程使用自定義View實(shí)現(xiàn)水波進(jìn)度效果示例
這篇文章主要介紹了Android編程使用自定義View實(shí)現(xiàn)水波進(jìn)度效果,結(jié)合實(shí)例形式詳細(xì)分析了Android水波動(dòng)畫效果的具體實(shí)現(xiàn)步驟與相關(guān)注意事項(xiàng),需要的朋友可以參考下2017-01-01Android啟動(dòng)頁廣告(騰訊廣告聯(lián)盟)解決方法及源碼下載
這篇文章主要介紹了Android啟動(dòng)頁廣告(騰訊廣告聯(lián)盟)解決方法的相關(guān)資料,啟動(dòng)頁幾乎成為了每個(gè)app的標(biāo)配,有些商家在啟動(dòng)頁中增加了開屏廣告以此帶來更多的收入,需要的朋友可以參考下2017-03-03Android Notification實(shí)現(xiàn)動(dòng)態(tài)顯示通話時(shí)間
這篇文章主要為大家詳細(xì)介紹了Android Notification實(shí)現(xiàn)動(dòng)態(tài)顯示通話時(shí)間,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09Android 實(shí)現(xiàn)仿網(wǎng)絡(luò)直播彈幕功能詳解及實(shí)例
這篇文章主要介紹了Android 實(shí)現(xiàn)仿網(wǎng)絡(luò)直播彈幕功能詳解的相關(guān)資料,并附實(shí)例代碼及實(shí)現(xiàn)效果圖,需要的朋友可以參考下2016-11-11