Android應(yīng)用借助LinearLayout實(shí)現(xiàn)垂直水平居中布局
首先說(shuō)的是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中圖片加載到內(nèi)存的實(shí)例代碼
這篇文章主要介紹了android中圖片加載到內(nèi)存的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-09-09
Libgdx解決部分Android機(jī)型鎖屏崩潰的方法
今天小編就為大家分享一篇關(guān)于Libgdx解決部分Android機(jī)型鎖屏崩潰的方法,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2018-10-10
android自定義進(jìn)度條漸變色View的實(shí)例代碼
這篇文章主要介紹了android自定義進(jìn)度條漸變色View的實(shí)例代碼,有需要的朋友可以參考一下2014-01-01
Android入門之使用SimpleAdapter實(shí)現(xiàn)復(fù)雜界面布局
這篇文章主要為大家詳細(xì)介紹了Android如何使用SimpleAdapter實(shí)現(xiàn)復(fù)雜的界面布局,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)Android有一定的幫助,需要的可以參考一下2022-11-11
react native打包apk文件安裝好之后進(jìn)入應(yīng)用閃退的解決方案
這篇文章主要介紹了react native打包apk文件安裝好之后進(jìn)入應(yīng)用閃退的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09
Android仿一號(hào)店貨物詳情輪播圖動(dòng)畫效果
這篇文章主要為大家詳細(xì)介紹了Android-仿一號(hào)店貨物詳情輪播圖動(dòng)畫效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06
Android實(shí)現(xiàn)動(dòng)畫效果詳解
這篇文章主要介紹了Android實(shí)現(xiàn)動(dòng)畫效果詳解,目前Android平臺(tái)提供了Tween動(dòng)畫和Frame動(dòng)畫,實(shí)現(xiàn)這兩類動(dòng)畫有兩種方式:一種使用XML文件(文件放在res/anim),一種直接代碼搞定,需要的朋友可以參考下2015-07-07

