Android gravity 和 layout_gravity区别
2011-02-12 16:21
302 查看
Strictly speaking android:gravity is not a Layout Param. The android:gravity is really an attribute of the View Group. It controls the way the contents of the View Group will be positioned horizontally and vertically.
android:layout_gravity Layout Param
The android:layout_gravity is a Layout Param. Not all View Groups support this Layout Param. See the documentation to find out which Layout Params
are supported by a particular View Group. Linear Layout does support android:layout_gravity Layout Param.
For a horizontal Linear Layout the following values make sense:
* top
* center
* bottom
That is because the children of a horizontal Linear Layout are layed out horizontally one after the other. Only thing can be controlled using the
android:layout_gravity is how a child view is positioned vertically.
In the above example the top Linear Layout is a horizontal Linear Layout. Setting the android:layout_gravity=top on the l_g=top Button has an
effect of positioning it at the top. Setting the android:layout_gravity=center on the l_g=center Button has an effect of positioning it at the
vertical center. Setting the android:layout_gravity=bottom on the l_g=bottom Button has an effect of positioning it at the bottom.
For a vertical Linear Layout the following values make sense:
* left
* center
* right
That is because the children of a vertical Linear Layout are layed out vertically one below the other. Only thing can be controlled using the
android:layout_gravity is how a child view is positioned horizontally.
In the about example the bottom Linear Layout is a vertical Linear Layout. Setting the android:layout_gravity=left on the l_g=left Button has an
effect of positioning it at the left. Setting the android:layout_gravity=center on the l_g=center Button has an effect of positioning it at the
horizontal center. Setting the android:layout_gravity=right on the l_g=right Button has an effect of positioning it at the right.
android:layout_gravity Layout Param
The android:layout_gravity is a Layout Param. Not all View Groups support this Layout Param. See the documentation to find out which Layout Params
are supported by a particular View Group. Linear Layout does support android:layout_gravity Layout Param.
For a horizontal Linear Layout the following values make sense:
* top
* center
* bottom
That is because the children of a horizontal Linear Layout are layed out horizontally one after the other. Only thing can be controlled using the
android:layout_gravity is how a child view is positioned vertically.
In the above example the top Linear Layout is a horizontal Linear Layout. Setting the android:layout_gravity=top on the l_g=top Button has an
effect of positioning it at the top. Setting the android:layout_gravity=center on the l_g=center Button has an effect of positioning it at the
vertical center. Setting the android:layout_gravity=bottom on the l_g=bottom Button has an effect of positioning it at the bottom.
For a vertical Linear Layout the following values make sense:
* left
* center
* right
That is because the children of a vertical Linear Layout are layed out vertically one below the other. Only thing can be controlled using the
android:layout_gravity is how a child view is positioned horizontally.
In the about example the bottom Linear Layout is a vertical Linear Layout. Setting the android:layout_gravity=left on the l_g=left Button has an
effect of positioning it at the left. Setting the android:layout_gravity=center on the l_g=center Button has an effect of positioning it at the
horizontal center. Setting the android:layout_gravity=right on the l_g=right Button has an effect of positioning it at the right.
相关文章推荐
- Android布局中layout_gravity和gravity区别
- android:gravity和android:layout_gravity区别
- android gravity和layout_gravity区别
- Android layout_gravity和gravity区别
- 王立平--android:gravity与android:layout_gravity区别
- android:gravity和android:layout_gravity区别
- android:gravity和android:layout_gravity区别
- android:gravity和android:layout_gravity区别
- android:gravity和android:layout_gravity区别
- android:gravity和android:layout_gravity区别
- 【android初学日志】gravity 和 layout_gravity区别
- android:gravity与android:layout_gravity区别
- 在程序中设置android:gravity 和 android:layout_Gravity属性
- Android中gravity与layout_gravity的使用区别分析
- 抽屉的布局 android:layout_gravity="start"
- ScrollView中为什么android:layout_gravity="center_horizontal"不管用呢?
- android的layout_gravity
- Android之android:gravity和android:layout_gravity属性
- android layout_gravity失效的问题
- android:layout_gravity="bottom"不起作用问题