Android布局管理器(線性布局)

來源:互聯網
上載者:User

標籤:

線性布局有LinearLayout類來代表,Android的線性布局和Swing的Box有點相似(他們都會將容器裡面的組件一個接一個的排列起來),LinearLayout中,使用android:orientation屬性控制布局是水平還是豎直布局(vertical水平,horizontal豎直)

XML屬性

相關方法

說明

android:baselineAligned

setBaselineAligned(boolean)

該屬性設定為false,將會阻止該布局管理器與它的子項目的基準對其

android:divider

setDividerDrawable(Drawable)

垂直布局兩個分按鈕之間的分割條

android:gravity

setGravity(int)

設定布局管理器內,組件的對齊,屬性支援:top,left,right,center_vertical,fill_vertical等

android:measureWithLargestChild

setMeasureWithLargestChildEnabled(boolean)

當該屬性設定為true時候,所有帶權重的子項目,都會具有最大子項目的最小尺寸

android:orientation

setOrientation(int)

設定布局管理器內,組件的對齊,horizontal:水平排列,vertical:垂直排列

 

LinearLayout子項目常用的XML屬性

XML屬性

相關方法

說明

Android:layout_gravity

 

指定該子項目在LinearLayout中的對齊

Android:layout_weight

 

指定該子項目在LinearLayout中所佔的權重

屬性具體效果:

  1. android:baselineAligned屬性
    <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:baselineAligned="false"    android:orientation="horizontal"    tools:context="com.example.layouttest.MainActivity" >    <TextView         android:id="@+id/t1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="第一個Text"/>        <Button         android:id="@+id/btn1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="第一個Bton"/>        <TextView         android:id="@+id/t2"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="第二個Text"/></LinearLayout>

  2. android:gravity屬性
    <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"    android:gravity="right"    tools:context="com.example.layouttest.MainActivity" >    <TextView         android:id="@+id/t1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="第一個Text"/>        <Button         android:id="@+id/btn1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="第一個Bton"/>        <TextView         android:id="@+id/t2"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="第二個Text"/></LinearLayout>

Android布局管理器(線性布局)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.