Android: Gravity/Android: layout_gravityDifferences:
Android: gravity is used to set the position of the content in the view relative to the view. For example, set the text in the button to the left and center of the view. Android: layout_gravity is used to set the relative position of the view and its parent view. For example, you can set the relative position of the button in layout: center the screen and center horizontally.
In practice, it is found that Android: gravity and Android: layout_gravity are used simultaneously:
< Textview
Android: ID = "@ + ID/text_displayed"
Android: gravity = "Center" // Set the center position of the text in textview
Android: visibility = "Invisible"
Android: layout_width = "Fill_parent"
Android: layout_height = "Wrap_content"
Android: layout_gravity = "Center" // Set the textview position (framelayout): center the screen
/> Java Code Setting Android: gravity in is extremely simple, and the setgravity function is done: // This is equivalent to the Android: gravity attribute in the layout file.
Button.
Setgravity (Gravity. center );
Android: padding/Android: layout_marginDifferences:
Padding describes the problem from the perspective of the parent view. It specifies the distance between the content and the parent view. Margin describes the problem from the perspective of itself and specifies the distance between itself and other views (up and down). If there is only one view at the same level, the effect is basically the same as that of padding.