標籤: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