Android手機(jī)開發(fā) 使用線性布局和相對(duì)布局實(shí)現(xiàn)Button垂直水平居中
居中呢,這里分兩種不同布局方式的居中!分別是 LinearLayout 和RelativeLayout。
一、首先說的是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>
二、然后說的是RelativeLayout布局下的居中:
<RelativeLayout xmlns:Android="http://schemas.android.com/apk/res/android" Android:layout_width="fill_parent" Android:layout_height="fill_parent"> <Button Android:id="@+id/btngal" Android:layout_width="wrap_content" Android:layout_height="wrap_content" Android:gravity="center_horizontal" Android:textSize="20sp" Android:layout_alignParentBottom="true" Android:layout_centerHorizontal="true" Android:text="返回主界面" /> </RelativeLayout>
簡(jiǎn)單說明
Android:gravity="CENTER_VERTICAL“:這個(gè)是垂直居中對(duì)齊
Android:gravity="BOTTOM”:放在容器的底部
Android:gravity="CENTER“ :放在容器的中心
三、一行居中兩個(gè)按鈕的方法
方法1:
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" style="@android:style/ButtonBar"> <Button android:id="@+id/btn_listview" android:layout_height="wrap_content" android:layout_width="0dp" android:layout_weight="1" android:text="ListView"/> <Button android:id="@+id/btn_emptyview" android:layout_height="wrap_content" android:layout_width="0dp" android:layout_weight="1" android:text="EmptyView"/> </LinearLayout>
方法2:
<RelativeLayout android:id="@+id/relativeTop" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_centerHorizontal="true" > <Button android:id="@+id/btnGetMp3s" android:text="@string/strGetMp3List" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:layout_toLeftOf="@id/txtHide" /> <TextView android:id="@+id/txtHide" android:layout_width="25" android:layout_height="1" android:layout_centerHorizontal="true" /> <Button android:id="@+id/btnExitSys" android:text="@string/strExitSys" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/txtHide" /> </RelativeLayout>
相關(guān)文章
Android開發(fā)中使用WebView控件瀏覽網(wǎng)頁的方法詳解
這篇文章主要介紹了Android開發(fā)中使用WebView控件瀏覽網(wǎng)頁的方法,結(jié)合實(shí)例形式較為詳細(xì)的總結(jié)分析了Android WebView控件的功能、布局、設(shè)置、常用方法及相關(guān)操作技巧,需要的朋友可以參考下2017-10-10Android?NDK開發(fā)(C語言--聯(lián)合體與枚舉)
這篇文章主要介紹了Android?NDK開發(fā)C語言聯(lián)合體與枚舉,共用體是一種特殊的數(shù)據(jù)類型,允許您在相同的內(nèi)存位置存儲(chǔ)不同的數(shù)據(jù)類型。您可以定義一個(gè)帶有多成員的共用體,但是任何時(shí)候只能有一個(gè)成員帶有值。下面詳細(xì)介紹該內(nèi)容,需要的朋友可以參考一下2021-12-12AndroidStudio 實(shí)現(xiàn)加載字體資源的方法
這篇文章主要介紹了AndroidStudio 實(shí)現(xiàn)加載字體資源的方法的相關(guān)資料,這里提供了詳細(xì)的實(shí)現(xiàn)方法,需要的朋友可以參考下2016-11-11Android BottomSheet效果的兩種實(shí)現(xiàn)方式
這篇文章主要介紹了Android BottomSheet效果的兩種實(shí)現(xiàn)方式,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-08-08Android Bitmap和Drawable的對(duì)比
這篇文章主要介紹了Android Bitmap和Drawable的對(duì)比的相關(guān)資料,需要的朋友可以參考下2017-05-05Android仿天天動(dòng)聽歌曲自動(dòng)滾動(dòng)view
這篇文章主要為大家詳細(xì)介紹了Android仿天天動(dòng)聽歌曲自動(dòng)滾動(dòng)view的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-05-05Android利用Badge組件實(shí)現(xiàn)未讀消息小紅點(diǎn)
在?App?的運(yùn)營(yíng)中,活躍度是一個(gè)重要的指標(biāo),日活/月活……為了提高活躍度,就發(fā)明了小紅點(diǎn)。這一篇,來介紹一個(gè)徽標(biāo)(Badge)組件,能夠快速搞定應(yīng)用內(nèi)的小紅點(diǎn),希望對(duì)大家有所幫助2023-01-01Android手機(jī)衛(wèi)士之確認(rèn)密碼對(duì)話框
這篇文章主要為大家詳細(xì)介紹了Android手機(jī)衛(wèi)士之確認(rèn)密碼對(duì)話框,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10