Android: gravity: sets the content location on the control.
Android: layout_gravity: Set the display position of the control relative to the parent control.
See the following code snippet.
<? Xml version = "1.0" encoding = "UTF-8"?>
<! -- Android: gravity sets the text display position on the button, while android: layout_gravity sets the display position of the button in the layout. -->
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
<Button android: layout_width = "250dip"
Android: gravity = "right"
Android: layout_height = "wrap_content"
Android: text = "show me on the right"
Android: layout_gravity = "right"/>
</LinearLayout>
The result is that the text of the button is displayed on the right, and the button is displayed on the right of the screen. The running result is as follows: