欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android手機(jī)開發(fā) 使用線性布局和相對(duì)布局實(shí)現(xiàn)Button垂直水平居中

 更新時(shí)間:2016年05月25日 09:22:50   作者:秦風(fēng)  
本文主要結(jié)合自己的理解分別對(duì)使用LinearLayout和RelativeLayout兩種方式實(shí)現(xiàn)居中做了總結(jié),希望對(duì)大家有所幫助。

居中呢,這里分兩種不同布局方式的居中!分別是 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)頁的方法詳解

    這篇文章主要介紹了Android開發(fā)中使用WebView控件瀏覽網(wǎng)頁的方法,結(jié)合實(shí)例形式較為詳細(xì)的總結(jié)分析了Android WebView控件的功能、布局、設(shè)置、常用方法及相關(guān)操作技巧,需要的朋友可以參考下
    2017-10-10
  • Android?NDK開發(fā)(C語言--聯(lián)合體與枚舉)

    Android?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-12
  • AndroidStudio 實(shí)現(xiàn)加載字體資源的方法

    AndroidStudio 實(shí)現(xiàn)加載字體資源的方法

    這篇文章主要介紹了AndroidStudio 實(shí)現(xiàn)加載字體資源的方法的相關(guān)資料,這里提供了詳細(xì)的實(shí)現(xiàn)方法,需要的朋友可以參考下
    2016-11-11
  • Android BottomSheet效果的兩種實(shí)現(xiàn)方式

    Android BottomSheet效果的兩種實(shí)現(xiàn)方式

    這篇文章主要介紹了Android BottomSheet效果的兩種實(shí)現(xiàn)方式,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-08-08
  • Android Bitmap和Drawable的對(duì)比

    Android Bitmap和Drawable的對(duì)比

    這篇文章主要介紹了Android Bitmap和Drawable的對(duì)比的相關(guān)資料,需要的朋友可以參考下
    2017-05-05
  • Android仿天天動(dòng)聽歌曲自動(dòng)滾動(dòng)view

    Android仿天天動(dòng)聽歌曲自動(dòng)滾動(dòng)view

    這篇文章主要為大家詳細(xì)介紹了Android仿天天動(dòng)聽歌曲自動(dòng)滾動(dòng)view的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-05-05
  • Android利用Badge組件實(shí)現(xiàn)未讀消息小紅點(diǎn)

    Android利用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-01
  • Android封裝Banner控件方法介紹

    Android封裝Banner控件方法介紹

    android-banner實(shí)現(xiàn)了一般banner循環(huán)輪播的效果,一頁只顯示一張圖片,也可以一頁顯示一張圖和相鄰兩個(gè)圖片的一部分,此項(xiàng)目?jī)H僅是banner展示圖片,沒有多余的諸如指示器、頁面切換動(dòng)畫等效果代碼,詳見效果圖和案例代碼
    2023-03-03
  • Android首頁無限輪播功能的示例代碼

    Android首頁無限輪播功能的示例代碼

    這篇文章主要介紹了Android首頁無限輪播功能的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-06-06
  • Android手機(jī)衛(wèi)士之確認(rèn)密碼對(duì)話框

    Android手機(jī)衛(wèi)士之確認(rèn)密碼對(duì)話框

    這篇文章主要為大家詳細(xì)介紹了Android手機(jī)衛(wèi)士之確認(rèn)密碼對(duì)話框,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-10-10

最新評(píng)論