android:gravity的属性官方说明如下:

public static final int AXIS_CLIP

Since: API Level 3 Raw bit controlling whether the right/bottom edge is clipped to its container, based on the gravity direction being applied. Constant Value: 8 (0x00000008)

public static final int AXIS_PULL_AFTER

Since: API Level 1 Raw bit controlling how the right/bottom edge is placed. Constant Value: 4 (0x00000004)

public static final int AXIS_PULL_BEFORE

Since: API Level 1 Raw bit controlling how the left/top edge is placed. Constant Value: 2 (0x00000002)

public static final int AXIS_SPECIFIED

Since: API Level 1 Raw bit indicating the gravity for an axis has been specified. Constant Value: 1 (0x00000001)

public static final int AXIS_X_SHIFT

Since: API Level 1 Bits defining the horizontal axis. Constant Value: 0 (0x00000000)

public static final int AXIS_Y_SHIFT

Since: API Level 1 Bits defining the vertical axis. Constant Value: 4 (0x00000004)

public static final int BOTTOM

Since: API Level 1 Push object to the bottom of its container, not changing its size. Constant Value: 80 (0x00000050)

public static final int CENTER

Since: API Level 1 Place the object in the center of its container in both the vertical and horizontal axis, not changing its size. Constant Value: 17 (0x00000011)

public static final int CENTER_HORIZONTAL

Since: API Level 1 Place object in the horizontal center of its container, not changing its size. Constant Value: 1 (0x00000001)

public static final int CENTER_VERTICAL

Since: API Level 1 Place object in the vertical center of its container, not changing its size. Constant Value: 16 (0x00000010)

public static final int CLIP_HORIZONTAL

Since: API Level 3 Flag to clip the edges of the object to its container along the horizontal axis. Constant Value: 8 (0x00000008)

public static final int CLIP_VERTICAL

Since: API Level 3 Flag to clip the edges of the object to its container along the vertical axis. Constant Value: 128 (0x00000080)

public static final int DISPLAY_CLIP_HORIZONTAL

Since: API Level 3 Special constant to enable clipping to an overall display along the horizontal dimension. This is not applied by default by apply(int, int, int, Rect, int, int, Rect); you must do so yourself by calling applyDisplay(int, Rect, Rect). Constant Value: 16777216 (0x01000000)

public static final int DISPLAY_CLIP_VERTICAL

Since: API Level 3 Special constant to enable clipping to an overall display along the vertical dimension. This is not applied by default by apply(int, int, int, Rect, int, int, Rect); you must do so yourself by calling applyDisplay(int, Rect, Rect). Constant Value: 268435456 (0x10000000)

public static final int END

Since: API Level 14 Push object to x-axis position at the end of its container, not changing its size. Constant Value: 8388613 (0x00800005)

public static final int FILL

Since: API Level 1 Grow the horizontal and vertical size of the object if needed so it completely fills its container. Constant Value: 119 (0x00000077)

public static final int FILL_HORIZONTAL

Since: API Level 1 Grow the horizontal size of the object if needed so it completely fills its container. Constant Value: 7 (0x00000007)

public static final int FILL_VERTICAL

Since: API Level 1 Grow the vertical size of the object if needed so it completely fills its container. Constant Value: 112 (0x00000070)

public static final int HORIZONTAL_GRAVITY_MASK

Since: API Level 1 Binary mask to get the absolute horizontal gravity of a gravity. Constant Value: 7 (0x00000007)

public static final int LEFT

Since: API Level 1 Push object to the left of its container, not changing its size. Constant Value: 3 (0x00000003)

public static final int NO_GRAVITY

Since: API Level 1 Constant indicating that no gravity has been set Constant Value: 0 (0x00000000)

public static final int RELATIVE_HORIZONTAL_GRAVITY_MASK

Since: API Level 14 Binary mask for the horizontal gravity and script specific direction bit. Constant Value: 8388615 (0x00800007)

public static final int RELATIVE_LAYOUT_DIRECTION

Since: API Level 14 Raw bit controlling whether the layout direction is relative or not (START/END instead of absolute LEFT/RIGHT). Constant Value: 8388608 (0x00800000)

public static final int RIGHT

Since: API Level 1 Push object to the right of its container, not changing its size. Constant Value: 5 (0x00000005)

public static final int START

Since: API Level 14 Push object to x-axis position at the start of its container, not changing its size. Constant Value: 8388611 (0x00800003)

public static final int TOP

Since: API Level 1 Push object to the top of its container, not changing its size. Constant Value: 48 (0x00000030)

public static final int VERTICAL_GRAVITY_MASK

Since: API Level 1 Binary mask to get the vertical gravity of a gravity. Constant Value: 112 (0x00000070) 效果图1: 布局文件xml内容如下: [html] view plain copy
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:orientation="vertical">
  6. <TextViewandroid:id="@+id/TextView01"
  7. android:layout_width="fill_parent"
  8. android:layout_height="35dp"
  9. android:text="top"
  10. android:gravity="top"
  11. android:textColor="#ffffff"
  12. android:background="#ff0000"
  13. android:layout_margin="1px"/>
  14. <TextViewandroid:id="@+id/TextView02"
  15. android:layout_width="fill_parent"
  16. android:layout_height="35dp"
  17. android:text="bottom"
  18. android:gravity="bottom"
  19. android:textColor="#ffffff"
  20. android:background="#ff0000"
  21. android:layout_margin="1px"/>
  22. <TextViewandroid:id="@+id/TextView03"
  23. android:layout_width="fill_parent"
  24. android:layout_height="35dp"
  25. android:text="left"
  26. android:gravity="left"
  27. android:textColor="#ffffff"
  28. android:background="#ff0000"
  29. android:layout_margin="1px"/>
  30. <TextViewandroid:id="@+id/TextView04"
  31. android:layout_width="fill_parent"
  32. android:layout_height="35dp"
  33. android:text="right"
  34. android:gravity="right"
  35. android:textColor="#ffffff"
  36. android:background="#ff0000"
  37. android:layout_margin="1px"/>
  38. <TextViewandroid:id="@+id/TextView05"
  39. android:layout_width="fill_parent"
  40. android:layout_height="35dp"
  41. android:text="center_vertical"
  42. android:gravity="center_vertical"
  43. android:textColor="#ffffff"
  44. android:background="#ff0000"
  45. android:layout_margin="1px"/>
  46. <TextViewandroid:id="@+id/TextView06"
  47. android:layout_width="fill_parent"
  48. android:layout_height="35dp"
  49. android:text="fill_vertical"
  50. android:gravity="fill_vertical"
  51. android:textColor="#ffffff"
  52. android:background="#ff0000"
  53. android:layout_margin="1px"/>
  54. <TextViewandroid:id="@+id/TextView07"
  55. android:layout_width="fill_parent"
  56. android:layout_height="35dp"
  57. android:text="center_horizontal"
  58. android:gravity="center_horizontal"
  59. android:textColor="#ffffff"
  60. android:background="#ff0000"
  61. android:layout_margin="1px"/>
  62. <TextViewandroid:id="@+id/TextView08"
  63. android:layout_width="fill_parent"
  64. android:layout_height="35dp"
  65. android:text="fill_horizontal"
  66. android:gravity="fill_horizontal"
  67. android:textColor="#ffffff"
  68. android:background="#ff0000"
  69. android:layout_margin="1px"/>
  70. <TextViewandroid:id="@+id/TextView09"
  71. android:layout_width="fill_parent"
  72. android:layout_height="35dp"
  73. android:text="center"
  74. android:gravity="center"
  75. android:textColor="#ffffff"
  76. android:background="#ff0000"
  77. android:layout_margin="1px"/>
  78. <TextViewandroid:id="@+id/TextView10"
  79. android:layout_width="fill_parent"
  80. android:layout_height="35dp"
  81. android:text="fill"
  82. android:gravity="fill"
  83. android:textColor="#ffffff"
  84. android:background="#ff0000"
  85. android:layout_margin="1px"/>
  86. <TextViewandroid:id="@+id/TextView11"
  87. android:layout_width="fill_parent"
  88. android:layout_height="35dp"
  89. android:text="clip_vertical"
  90. android:gravity="clip_vertical"
  91. android:textColor="#ffffff"
  92. android:background="#ff0000"
  93. android:layout_margin="1px"/>
  94. <TextViewandroid:id="@+id/TextView12"
  95. android:layout_width="fill_parent"
  96. android:layout_height="35dp"
  97. android:text="clip_horizontal"
  98. android:gravity="clip_horizontal"
  99. android:textColor="#ffffff"
  100. android:background="#ff0000"
  101. android:layout_margin="1px"/>
  102. </LinearLayout>
效果图2: xml布局文件如下: [html] view plain copy
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:orientation="vertical">
  6. <TextViewandroid:id="@+id/TextView01"
  7. android:layout_width="fill_parent"
  8. android:layout_height="50dp"
  9. android:text="top"
  10. android:gravity="top"
  11. android:textColor="#ffffff"
  12. android:background="#00ff00"
  13. android:layout_margin="2px"/>
  14. <TextViewandroid:id="@+id/TextView02"
  15. android:layout_width="fill_parent"
  16. android:layout_height="50dp"
  17. android:text="bottom"
  18. android:gravity="bottom"
  19. android:textColor="#ffffff"
  20. android:background="#00ff00"
  21. android:layout_margin="2px"/>
  22. <TextViewandroid:id="@+id/TextView03"
  23. android:layout_width="fill_parent"
  24. android:layout_height="50dp"
  25. android:text="left"
  26. android:gravity="left"
  27. android:textColor="#ffffff"
  28. android:background="#00ff00"
  29. android:layout_margin="2px"/>
  30. <TextViewandroid:id="@+id/TextView04"
  31. android:layout_width="fill_parent"
  32. android:layout_height="50dp"
  33. android:text="right"
  34. android:gravity="right"
  35. android:textColor="#ffffff"
  36. android:background="#00ff00"
  37. android:layout_margin="2px"/>
  38. <TextViewandroid:id="@+id/TextView05"
  39. android:layout_width="fill_parent"
  40. android:layout_height="50dp"
  41. android:text="center_vertical"
  42. android:gravity="center_vertical"
  43. android:textColor="#ffffff"
  44. android:background="#00ff00"
  45. android:layout_margin="2px"/>
  46. <TextViewandroid:id="@+id/TextView06"
  47. android:layout_width="fill_parent"
  48. android:layout_height="50dp"
  49. android:text="fill_vertical"
  50. android:gravity="fill_vertical"
  51. android:textColor="#ffffff"
  52. android:background="#00ff00"
  53. android:layout_margin="2px"/>
  54. <TextViewandroid:id="@+id/TextView07"
  55. android:layout_width="fill_parent"
  56. android:layout_height="50dp"
  57. android:text="center_horizontal"
  58. android:gravity="center_horizontal"
  59. android:textColor="#ffffff"
  60. android:background="#00ff00"
  61. android:layout_margin="2px"/>
  62. <TextViewandroid:id="@+id/TextView08"
  63. android:layout_width="fill_parent"
  64. android:layout_height="50dp"
  65. android:text="fill_horizontal"
  66. android:gravity="fill_horizontal"
  67. android:textColor="#ffffff"
  68. android:background="#00ff00"
  69. android:layout_margin="2px"/>
  70. <TextViewandroid:id="@+id/TextView09"
  71. android:layout_width="fill_parent"
  72. android:layout_height="50dp"
  73. android:text="center"
  74. android:gravity="center"
  75. android:textColor="#ffffff"
  76. android:background="#00ff00"
  77. android:layout_margin="2px"/>
  78. <TextViewandroid:id="@+id/TextView10"
  79. android:layout_width="fill_parent"
  80. android:layout_height="50dp"
  81. android:text="fill"
  82. android:gravity="fill"
  83. android:textColor="#ffffff"
  84. android:background="#00ff00"
  85. android:layout_margin="2px"/>
  86. <TextViewandroid:id="@+id/TextView11"
  87. android:layout_width="fill_parent"
  88. android:layout_height="50dp"
  89. android:text="clip_vertical"
  90. android:gravity="clip_vertical"
  91. android:textColor="#ffffff"
  92. android:background="#00ff00"
  93. android:layout_margin="2px"/>
  94. <TextViewandroid:id="@+id/TextView12"
  95. android:layout_width="fill_parent"
  96. android:layout_height="50dp"
  97. android:text="clip_horizontal"
  98. android:gravity="clip_horizontal"
  99. android:textColor="#ffffff"
  100. android:background="#00ff00"
  101. android:layout_margin="2px"/>
  102. </LinearLayout>






更多相关文章

  1. [转]Android(安卓)源代码结构
  2. Android(安卓)资源文件中@、@android:type、@*、?、@+含义和区别
  3. Android(安卓)修改程序字体
  4. Android(安卓)xml资源文件中@、@android:type、@*、?、@+含义和区
  5. android字体的工作原理
  6. 老罗Android开发视频教程 (android解析xml文件 )3集集合
  7. android xml布局文件属性说明
  8. android 带文字的ImageButton
  9. centos下安装adb环境

随机推荐

  1. Android实现页面悬浮显示
  2. Android中的style和theme的用法
  3. ArcGIS for Android安装配置详解
  4. Android(安卓)TextView边框和背景,以及圆
  5. Android(安卓)源码编译 文件系统制作
  6. Android(安卓)webview加载富文本 屏幕简
  7. ubuntu下使用nginx和nginx-rtmp-module配
  8. android:giavity和layout_gravity的区别
  9. Android消息机制2-Handler(Native层)
  10. android电话处理