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. 时钟控件AnalogClock和DigitalClock
  5. 安卓基本常用控件: View
  6. android 开发-spinner下拉框控件的实现
  7. Android基本控件常用属性及方法
  8. Android UI控件学习笔记(二)
  9. Android按钮控件之RadioGroup和RadioButton

随机推荐

  1. 学 Win32 汇编[18]: 关于压栈(PUSH)与出
  2. 学用 ASP.Net 之 "字符串" (4): string
  3. 学 Win32 汇编[27] - 乘除指令: MUL、IMU
  4. 学 Win32 汇编[19]: 查看二进制等相关函
  5. 学用 ASP.Net 之 "字符串" (5): StringBu
  6. 学 Win32 汇编[29] - 串指令: MOVS*、CMP
  7. 学 Win32 汇编[30] - 条件及循环伪指令:
  8. 学用 ASP.Net 之 "字符串" (6): StringIn
  9. 学用 ASP.Net 之 System.Char 结构
  10. 学用 ASP.Net 之 System.Random 类