亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

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

簡單說明

Android:gravity="CENTER_VERTICAL“:這個是垂直居中對齊

Android:gravity="BOTTOM”:放在容器的底部

Android:gravity="CENTER“ :放在容器的中心

三、一行居中兩個按鈕的方法

方法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é)合實例形式較為詳細的總結(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)存位置存儲不同的數(shù)據(jù)類型。您可以定義一個帶有多成員的共用體,但是任何時候只能有一個成員帶有值。下面詳細介紹該內(nèi)容,需要的朋友可以參考一下
    2021-12-12
  • AndroidStudio 實現(xiàn)加載字體資源的方法

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

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

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

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

    Android Bitmap和Drawable的對比

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

    Android仿天天動聽歌曲自動滾動view

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

    Android利用Badge組件實現(xiàn)未讀消息小紅點

    在?App?的運營中,活躍度是一個重要的指標,日活/月活……為了提高活躍度,就發(fā)明了小紅點。這一篇,來介紹一個徽標(Badge)組件,能夠快速搞定應(yīng)用內(nèi)的小紅點,希望對大家有所幫助
    2023-01-01
  • Android封裝Banner控件方法介紹

    Android封裝Banner控件方法介紹

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

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

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

    Android手機衛(wèi)士之確認密碼對話框

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

最新評論