Android基礎TOP3:線性布局的特點,常用屬性,及權重值,androidtop3

來源:互聯網
上載者:User

Android基礎TOP3:線性布局的特點,常用屬性,及權重值,androidtop3

線性布局是一種讓視圖水平或者垂直布排列的布局;

常用屬性:

androuid:orientation :表示布局方向

  •  取值vertical表示垂直布局
  •  取值horizontal表示水平布局

android:gravity 表示視圖對齊

  • 內容包括 TOP,bottom,left,right,center_vertical,center_horizontal,center
  • 可以使用“|”分割填寫多個值

布局中的視圖可以使用如下多個屬性:

android:layout_gravity 表示單個視圖的對齊

android:layout_weight 表示單個視圖所在大小的比重

  • 當Layout_weight為0時候視圖大小自身確定
  • 當layout_weight大於0時,視圖線上性布局方向根據比重展開

代碼示範:

 1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3     android:layout_width="match_parent" 4     android:layout_height="match_parent" 5     android:orientation="horizontal" > 6     <Button  7         android:layout_width="200dp" 8         android:layout_height="100dp" 9         android:text="adaflkjn"10         android:gravity="bottom|center_horizontal"/>11 12 </LinearLayout>

android:gravity:是決定控制項內元素在某個位置
<Button         android:layout_width="200dp"        android:layout_height="100dp"        android:text="adaflkjn"        android:layout_gravity="center"/>

 

android:layout_gravity是本元素在父元素裡面顯示的位置

weight的應用

<EditText        android:layout_width="0dp"       android:layout_height="wrap_content"       android:layout_weight="1"       android:hint="sdaf"/>   <Button        android:layout_width="1dp"       android:layout_height="wrap_content"       android:layout_weight="0"       android:text="klndgjl"       />

 <TextView      android:layout_width="fill_parent"      android:layout_height="wrap_content"      android:layout_weight="0"      android:text="weight為0"      android:background="#FFF0F5"      />  <TextView      android:layout_width="fill_parent"      android:layout_height="wrap_content"      android:text="weight為1"       android:layout_weight="1"      android:background="#800080"      />   <TextView      android:layout_width="fill_parent"      android:layout_height="wrap_content"      android:text="weight為4"       android:layout_weight="4"      android:background="#4B0082"      />

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.