gravity 与 layout_gravity 的区别

android:gravity sets the gravity of the content of the View its used on.
android:layout_gravity sets the gravity of the View or Layout in its parent.

简单来说就是

  • android:gravity - 控件内部子控件的位置
  • android:layout_gravity - 在父控件中所处的位置

注意

Must be one or more (separated by '|') of the following constant values.

Constant Value Description
top 0x30 Push object to the top of its container, not changing its size.
bottom 0x50 Push object to the bottom of its container, not changing its size.
left 0x03 Push object to the left of its container, not changing its size.
right 0x05 Push object to the right of its container, not changing its size.
center_vertical 0x10 Place object in the vertical center of its container, not changing its size.
fill_vertical 0x70 Grow the vertical size of the object if needed so it completely fills its container.
center_horizontal 0x01 Place object in the horizontal center of its container, not changing its size.
fill_horizontal 0x07 Grow the horizontal size of the object if needed so it completely fills its container.
center 0x11 Place the object in the center of its container in both the vertical and horizontal axis, not changing its size.
fill 0x77 Grow the horizontal and vertical size of the object if needed so it completely fills its container.
clip_vertical 0x80 Additional option that can be set to have the top and/or bottom edges of the child clipped to its container's bounds. The clip will be based on the vertical gravity: a top gravity will clip the bottom edge, a bottom gravity will clip the top edge, and neither will clip both edges.
clip_horizontal 0x08 Additional option that can be set to have the left and/or right edges of the child clipped to its container's bounds. The clip will be based on the horizontal gravity: a left gravity will clip the right edge, a right gravity will clip the left edge, and neither will clip both edges.
start 0x00800003 Push object to the beginning of its container, not changing its size.
end 0x00800005 Push object to the end of its container, not changing its size.

更多相关文章

  1. Android(安卓)日期控件的简单实现
  2. android 分段显示文本颜色控件
  3. Android控件属性集锦
  4. Android学习--TextView和Button
  5. Android(安卓)两个可拖动的SeekBar 两点拖动
  6. android app content
  7. android学习之textView布局文件
  8. android2.x中android:layout_marginRight不起作用的解决办法
  9. 时钟控件AnalogClock和DigitalClock

随机推荐

  1. Android(安卓)Scripting Environment
  2. android开发 - 圆角和边框
  3. [Android]使用ActivityGroup来切换Activi
  4. Android 操作串口 (android serial port
  5. 屏蔽电信流氓广告造成的诡异的问题--Andr
  6. 当遇到百度和谷歌都不知道的技术问题时改
  7. android 中处理崩溃异常并重启程序
  8. android获取某应用的帧数据
  9. 最佳实践-android程序安全
  10. Android中有关Handler的使用详解