Android中有關佈局的幾個問題

1.android:gravity和android:layout_gravity區別

  android:gravity Specifies how to place the content of an object, both on the x- and y-axis, within the object itself.

  android:layout_gravity Standard gravity constant that a child can supply to its parent.


從名字上可以看到,android:gravity是對元素本身說的,元素本身的文本顯示在什麼地方靠着換個屬性設置,不過不設置默認是在左側的。android:layout_gravity是相對與它的父元素說的,說明元素顯示在父元素的什麼位置。


note:這兩個屬性不容易掌握,可是作用又很大(設置控件位置時候),建議多嘗試。


2.當LinearLayout的layout_oritentation設置爲horizontal ,並且裏面的控件使用了layout_width="fill_parent" ,第二組控件會擋在屏幕的右邊,那也就是看不到了。這種情況應該避免,建議裏面的控件使用layout_width="wrap_content'或者指定具體的像素值。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章