Android gravity 和 layout_gravity区别

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值