Gravity This English word is the meaning of the center of gravity, here means the docking position.
The difference between android:layout_gravity and android:gravity
As you can see from the name, Android:gravity is the element itself, where the text of the element itself is displayed in a different property setting, but not set by default on the left.
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.
Optional values
The optional values for these two properties are: Top, bottom, left, right, center_vertical, fill_vertical, Center_horizontal, fill_horizontal, center, fill, Clip_vertical.
And these properties are available in multiple selections, with the "|" Separate.
The default value for this is: Gravity.left
Descriptions of these properties:
From:
Http://androidmirror.com/guide/topics/resources/drawable-resource.html
Http://android.toolib.net/reference/android/graphics/drawable/ClipDrawable.html
Value |
Description |
Top |
Put the object at the top of it container, not changing its size. Places the object at the top of its container without changing its size. |
Bottom |
Put the object at the bottom of it container, not changing its size. Places the object at the bottom of its container, without changing its size. |
Left |
Put the object at the left edge of it container, not changing its size. Places the object on the left side of its container without changing its size. |
Right |
Put the object at the right edge of its container, not changing its size. Places the object on the right side of its container without changing its size. |
Center_vertical |
Place object in the vertical center of its container, not changing its size. Centers the object vertically without changing its size. Vertical alignment: Center-aligned vertically. |
Fill_vertical |
Grow the vertical size of the object if needed so it completely fills its container. When necessary, increase the vertical size of the object to fully fill its container. Vertical fill |
Center_horizontal |
Place object in the horizontal center of its container, not changing its size. Centers the object horizontally, without changing its size. Horizontal alignment: Center aligned horizontally |
Fill_horizontal |
Grow the horizontal size of the object if needed so it completely fills its container. When necessary, increase the horizontal size of the object to fully fill its container. Fill horizontally |
Center |
Place the object in the center of its container in both the vertical and horizontal axis, not changing its size. Centers the object horizontally, without changing its size. |
Fill |
Grow the horizontal and vertical size of the object if needed so it completely fills it container. This is the default. When necessary, increase the cross-portrait size of the object to fully fill its container. |
Clip_vertical |
Additional option that can is set to has the top and/or bottom edges of the child clipped to its container ' s bounds. The clip is based on the vertical gravity:a top gravity clips The bottom edge, a bottom gravity clips the top edge, and N Either clips both edges.
Additional options for cutting the contents of the top and/or bottom of the object according to the edges of the container. 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 cut apart. Crop vertically |
Clip_horizontal |
Additional option that can is set to has the left and/or right edges of the child clipped to its container ' s bounds. The clip is based on the horizontal gravity:a left gravity clips the right edge, a right gravity clips the left edge, and Neither clips both edges.
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 |
Simple memory: Horizontal are the horizontal direction of operation, that is, horizontal, vertical are the vertical direction of speculation, that is, vertical.
Questions about when LinearLayout will take effect
See also: Talk about layout_gravity and gravity
http://www.lephone.net/viewthread.php?tid=325
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.
The difference between android:layout_gravity and android:gravity