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

Android應(yīng)用借助LinearLayout實現(xiàn)垂直水平居中布局

 更新時間:2016年04月13日 14:46:05   作者:andie_guo  
這篇文章主要介紹了Android應(yīng)用借助LinearLayout實現(xiàn)垂直水平居中布局的方法,文中列舉了LinearLayout線性布局下居中相關(guān)的幾個重要參數(shù),需要的朋友可以參考下

首先說的是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>  

要實現(xiàn)垂直水平居中,幾個基本參數(shù)值得注意:
1、android:orientation="vertical"表示該布局下的元素垂直排列;
2、android:layout_gravity="center_horizontal"表示該布局在父布局里水平居中,此時其父布局必須擁有android:orientation="vertical"屬性;
3、android:layout_gravity="center_vertical"表示該布局在父布局里垂直居中,此時其父布局必須應(yīng)設(shè)置成android:orientation="horizontal"屬性(默認為該屬性),且其父布局的高度應(yīng)設(shè)置為android:layout_height="fill_parent"屬性;
4、android:gravity="center_horizontal"表示該布局下的元素水平居中;

線性布局垂直水平居中布局文件實例:

<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> 

相關(guān)文章

  • Android實現(xiàn)自定義飄雪效果

    Android實現(xiàn)自定義飄雪效果

    隨著冬季的腳步越來越遠,南方的我今年就看了一場雪,下一場雪遙遙無期,那我們來實現(xiàn)一個自定義的 View,它能模擬雪花飄落的景象,所以本文給大家介紹了基于Android實現(xiàn)自定義飄雪效果,感興趣的朋友可以參考下
    2024-01-01
  • Android如何高效顯示較大的Bitmaps

    Android如何高效顯示較大的Bitmaps

    這篇文章主要為大家詳細介紹了Android如何高效顯示較大Bitmaps的方法,感興趣的小伙伴們可以參考一下
    2016-05-05
  • android中intent傳遞list或者對象的方法

    android中intent傳遞list或者對象的方法

    這篇文章主要介紹了android中intent傳遞list或者對象的方法,分析羅列了常用的幾種方法,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-01-01
  • Android ListView之EfficientAdapte的使用詳解

    Android ListView之EfficientAdapte的使用詳解

    這篇文章主要介紹了Android ListView之EfficientAdapte的使用詳解的相關(guān)資料,這里介紹EfficientAdapter 的使用方法,需要的朋友可以參考下
    2017-08-08
  • Android中比較兩個圖片是否一致的問題

    Android中比較兩個圖片是否一致的問題

    這篇文章主要介紹了Android中比較兩個圖片是否一致的問題,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-10-10
  • Android編程使用自定義View實現(xiàn)水波進度效果示例

    Android編程使用自定義View實現(xiàn)水波進度效果示例

    這篇文章主要介紹了Android編程使用自定義View實現(xiàn)水波進度效果,結(jié)合實例形式詳細分析了Android水波動畫效果的具體實現(xiàn)步驟與相關(guān)注意事項,需要的朋友可以參考下
    2017-01-01
  • 詳解Android 進程

    詳解Android 進程

    這篇文章主要介紹了Android 進程的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)Android開發(fā),感興趣的朋友可以了解下
    2020-08-08
  • Android啟動頁廣告(騰訊廣告聯(lián)盟)解決方法及源碼下載

    Android啟動頁廣告(騰訊廣告聯(lián)盟)解決方法及源碼下載

    這篇文章主要介紹了Android啟動頁廣告(騰訊廣告聯(lián)盟)解決方法的相關(guān)資料,啟動頁幾乎成為了每個app的標配,有些商家在啟動頁中增加了開屏廣告以此帶來更多的收入,需要的朋友可以參考下
    2017-03-03
  • Android Notification實現(xiàn)動態(tài)顯示通話時間

    Android Notification實現(xiàn)動態(tài)顯示通話時間

    這篇文章主要為大家詳細介紹了Android Notification實現(xiàn)動態(tài)顯示通話時間,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • Android 實現(xiàn)仿網(wǎng)絡(luò)直播彈幕功能詳解及實例

    Android 實現(xiàn)仿網(wǎng)絡(luò)直播彈幕功能詳解及實例

    這篇文章主要介紹了Android 實現(xiàn)仿網(wǎng)絡(luò)直播彈幕功能詳解的相關(guān)資料,并附實例代碼及實現(xiàn)效果圖,需要的朋友可以參考下
    2016-11-11

最新評論