android:gravity與android:layout_gravity

來源:互聯網
上載者:User

標籤:android   blog   http   ext   com   html   

 

LinearLayout有兩個非常相似的屬性:android:gravity與android:layout_gravity。他們的區別在於:android:gravity用於設定View組件的對齊,而android:layout_gravity用於設定Container組件的對齊。

通俗點說就是:

android:gravity屬性是對該view 內容的限定.比如一個button 上面的text. 你可以設定該text 在view的靠左,靠右等位置.該屬性就幹了這個. 
android:layout_gravity是用來設定該view相對與起父view 的位置.比如一個button 在linearlayout裡,你想把該button放在靠左靠右等位置就可以通過該屬性設定. 
我們弄個最外布局,然后里麵包了幾個布局,如果要使這幾個布局都靠底,就可以在最外布局的屬性裡設定androi:gravity="botton" 因為gravity是對裡面的內容起作用

 

 

哪些布局支援? 應用限制?

 

當作為父layout的LinearLayout的屬性為androidrientation="vertical" 的時候,android:layout_gravity="?"這裡設為橫向的時候才會生效。比如:left,right,center_horizontal等

當作為父layout的LinearLayout的屬性為androidrientation="horizental" 的時候,android:layout_gravity="?"這裡設為縱向的時候才會生效。比如:top,bottom,center_vertical等;

有一個比較特殊的是center,不管是橫向還是縱向的時候,它總有一個方向起作用

lianjie:http://www.cnblogs.com/xiaoran1129/archive/2013/03/26/2982733.html

 

 

 

 

 

 

 

聯繫我們

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