android的LinearLayout

來源:互聯網
上載者:User

標籤:android   布局   layout   

LinearLayout也是ViewGroup的子類,算是個容器了。
兩個最重要的xml屬性: android:layout_gravity      android:gravity
還有一個屬性,是這兩個貨的爺。android:orientation。
下面來討論了。

1:<LinearLayout android:layout_width="fill_parent"android:layout_height="100dp"android:orientation="vertical">

當布局方向是垂直的時候。就定義了兒子們,你們必須排成豎的。而且是按順序來,不準插隊。。。。。。。

android:gravity     這貨也可以叫他爸爸gravity  。專門控制兒子的。控制對兒子的引力。

比如,我想讓一排兒子們在左邊,在右邊,在。。。。。。。一供有9個位置,,,,我沒說錯吧。


android:layout_gravity       這貨是每個兒子對自己引力的控制。

麻痹,android:gravity  不是想讓我們排成一排,排的整齊嗎。我就不,

<LinearLayout        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:gravity="center"        android:orientation="vertical" >        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_gravity="left"            android:text="nihao" />        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="nihao" />        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="nihao" />        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="nihao" />    </LinearLayout>

這貨就跑到左邊去了。它有想了,這尼嗎我們一群兒子不還是在垂直方向的中間嗎。不行,我要到左上方。好|top。結果呢。還是一樣在左中。


也就是爸爸的gravity把一群兒子們限制在這9個位置中。。。。。。如果一個兒子不聽話。想跑。也可以。他們的大爺把orientation限制死了。。。兒子你想跑。只能往orientation未設定的方向跑。。。。。我的例子中,只能往水平方向跑。


還有一句話。就是爸爸沒設定 android:gravity。怎麼辦。好辦呀。直接給我到左上方去。按個排吧。


可是,這完全滿足不了我的需求啊。我有時候不想一個挨一個的排。咋辦捏。。。。。。

好吧,android:weightSum       和 android:layout_weight出場了。

第一個是爸爸定義的。我的家產(空間)一共是這些。wrap_content是什麼意思呢,就是兒子夠吃的(空間)。

第二個,是兒子能分到多少家產(空間),那要是他已近wrap_content了。沒事。先佔著。

    <LinearLayout        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:gravity="center"        android:orientation="vertical"        android:weightSum="5" >        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_gravity="left"            android:text="nihao1" />        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_gravity="left|top"            android:text="nihao2" />        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="nihao3" />        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="nihao4" />    </LinearLayout>




android的LinearLayout

聯繫我們

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