Android android:gravity属性介绍及效果图

来源:互联网 发布:c#获取网页源码 编辑:程序博客网 时间:2024/04/30 01:19

Android android:gravity属性介绍及效果图

分类: Android 12752人阅读 评论(0)收藏 举报
androidlayoutapiobjectencodingxml

目录(?)[+]

  1. public static final int AXIS_CLIP
  2. public static final int AXIS_PULL_AFTER
  3. public static final int AXIS_PULL_BEFORE
  4. public static final int AXIS_SPECIFIED
  5. public static final int AXIS_X_SHIFT
  6. public static final int AXIS_Y_SHIFT
  7. public static final int BOTTOM
  8. public static final int CENTER
  9. public static final int CENTER_HORIZONTAL
  10. public static final int CENTER_VERTICAL
  11. public static final int CLIP_HORIZONTAL
  12. public static final int CLIP_VERTICAL
  13. public static final int DISPLAY_CLIP_HORIZONTAL
  14. public static final int DISPLAY_CLIP_VERTICAL
  15. public static final int END
  16. public static final int FILL
  17. public static final int FILL_HORIZONTAL
  18. public static final int FILL_VERTICAL
  19. public static final int HORIZONTAL_GRAVITY_MASK
  20. public static final int LEFT
  21. public static final int NO_GRAVITY
  22. public static final int RELATIVE_HORIZONTAL_GRAVITY_MASK
  23. public static final int RELATIVE_LAYOUT_DIRECTION
  24. public static final int RIGHT
  25. public static final int START
  26. public static final int TOP
  27. public static final int VERTICAL_GRAVITY_MASK

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

public static final intAXIS_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 intAXIS_PULL_AFTER

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

public static final intAXIS_PULL_BEFORE

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

public static final intAXIS_SPECIFIED

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

public static final intAXIS_X_SHIFT

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

public static final intAXIS_Y_SHIFT

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

public static final intBOTTOM

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

public static final intCENTER

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 intCENTER_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 intCENTER_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 intCLIP_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 intCLIP_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 intDISPLAY_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 byapply(int, int, int, Rect, int, int, Rect); you must do so yourself by callingapplyDisplay(int, Rect, Rect).
Constant Value: 16777216 (0x01000000)

public static final intDISPLAY_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 byapply(int, int, int, Rect, int, int, Rect); you must do so yourself by callingapplyDisplay(int, Rect, Rect).
Constant Value: 268435456 (0x10000000)

public static final intEND

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 intFILL

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 intFILL_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 intFILL_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 intHORIZONTAL_GRAVITY_MASK

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

public static final intLEFT

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

public static final intNO_GRAVITY

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

public static final intRELATIVE_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 intRELATIVE_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 intRIGHT

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

public static final intSTART

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 intTOP

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

public static final intVERTICAL_GRAVITY_MASK

Since: API Level 1
Binary mask to get the vertical gravity of a gravity.
Constant Value: 112 (0x00000070)
效果图1:
布局文件xml内容如下:
[html] view plaincopyprint?
  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 plaincopyprint?
  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>
0 0
原创粉丝点击