The difference between android:layout_gravity and Android:gravit?
Android:gravity is the position of the element that adjusts the contents of the elements themselves or the elements that contain them, which are displayed by default on the left side
Android:layout_gravity is relative to its parent element, stating where the element appears in the parent element.
For example, Button:android:layout_gravity represents the position of the button on the interface. The android:gravity represents the position of the word on the button on the button .
The optional values for these two properties are:
| Value |
Description |
| Top |
Places the object at the top of its container without changing its size. |
| Bottom |
Places the object at the bottom of its container, without changing its size. |
| Left |
Places the object on the left side of its container without changing its size. |
| Right |
Places the object on the right side of its container without changing its size. |
| Center_vertical |
Centers the object vertically without changing its size.
Vertical alignment: Center-aligned vertically. |
| Fill_vertical |
When necessary, increase the vertical size of the object to fully fill its container.
Vertical fill |
| Center_horizontal |
Centers the object horizontally, without changing its size.
Horizontal alignment: Center aligned horizontally |
| Fill_horizontal |
When necessary, increase the horizontal size of the object to fully fill its container.
Fill horizontally |
| Center |
Centers the object horizontally, without changing its size. |
| Fill |
When necessary, increase the cross-portrait size of the object to fully fill its container. |
|
additional options, which are used to cut the top of the object by the edges of the container and/ Or the bottom of the content. Clipping is based on its vertical alignment settings: When the top is aligned, the bottom is clipped, the top is clipped at the bottom, and the top and bottom are clipped.
vertical clipping |
| Clip_horizontal |
An additional option to cut the contents of the left and/or right of the object according to the edges of the container. Clipping is based on its horizontal alignment settings: Cut to the right when left aligned, cut to the left when aligned to the right, and cut to the left and right.
Horizontal Orientation Clipping |
For LinearLayout
When android:orientation= "vertical", only the horizontal setting will work, and the vertical setting will not work. That is: The left,right,center_horizontal is in force.
When android:orientation= "Horizontal", only the vertical setting will work, and the horizontal setting will not work. That is: The top,bottom,center_vertical is in force.
For Relativelayout
There is no android:layout_gravity attribute, such as to set up must use Android:layout_centerinparent or Android:layout_centerhorizontal or Android: Layout_centervertical
For Absolutelayout
There is no android:layout_gravity attribute, only the position of x, Y can be set
For Framelayout
The set center_vertical is centered vertically, while the center_horizontal is centered horizontally and Center is both horizontal and vertical
For Tablelayout
Each element is a row, setting the Android:layout_gravit property has no effect
The difference between android:layout_gravity and Android:gravit?