溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Android學習—LinearLayout布局中實現左右對齊

發布時間:2020-07-30 19:03:22 來源:網絡 閱讀:3961 作者:孤月2012 欄目:移動開發

在android中的控件LinearLayout 中的android:gravity="center"  屬性,要么是居左、居右、居中對齊,android:gravity="right" 和 android:gravity="left"  并不能達到雙控件的左右兩端對齊,

要實現兩端對齊方式,要采用 中間增加一個控件的方式實現 ,并設置屬性android:layout_weight="1",原因是設置android:layout_weight="1",就把控件均分了。

 

具體的布局文件如下:

Xml代碼 Android學習—LinearLayout布局中實現左右對齊 Android學習—LinearLayout布局中實現左右對齊Android學習—LinearLayout布局中實現左右對齊

  1. <?xml version="1.0″ encoding="utf-8″?>  

  2.   

  3. <LinearLayout        

  4.    android:layout_width="match_parent"        

  5.    android:layout_height="20dp"    

  6.    android:background="#EFEFEF"

  7.    android:orientation="horizontal">

  8.    <Button  

  9.            android:text="button1" 

  10.            android:layout_marginLeft="4dp"

  11.            android:id="@+id/btnlogin_main"

  12.            android:layout_height="20dp" 

  13.            android:layout_width="wrap_content" 

  14.            android:textSize="12dp"

  15.            android:background="#EFEFEF"

  16.            android:textColor="#404040">

  17.     </Button>

  18.     <TextView

  19.        android:layout_width="wrap_content"

  20.        android:layout_height="wrap_content"

  21.        android:layout_weight="1" />

  22.    <Button

  23.        android:id="@+id/btnSetting_Main"

  24.        android:layout_marginRight="4dp"

  25.        android:layout_width="wrap_content"

  26.        android:layout_height="20dp"

  27.        android:text="button2" 

  28.        android:textSize="12dp"

  29.            android:background="#EFEFEF"

  30.            android:textColor="#404040">

  31.    </Button>

  32. </LinearLayout>

 效果如圖:

   
       Android學習—LinearLayout布局中實現左右對齊

實現兩個button按鈕 兩端對齊


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女