Gravity's Chinese meaning is "center of gravity", that is, the view horizontal and vertical docking position
Android:gravity: Is the view control itself, is the text used to set the view itself should be displayed in the view where the default value is the left side
Android:layout_gravity: Sets the position of the element in the parent element relative to the parent element that includes the element being changed
For example, TextView:android:layout_gravity represents the position of TextView on the interface, android:gravity indicates where the TextView text is in TextView, and the default value is the left side
For example, the following examples
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:orientation=" vertical " android:layout_width=" Fill_parent " android:layout_height= "fill_parent" > <textview android:layout_width= "100dip" android:layout_height= "100dip" android:layout_gravity= "Bottom|center_ Horizontal " android:gravity=" Center|bottom " android:background= "#00FF00" android:text= "@string/textview" /> <Button android: Layout_width= "100dip" android:layout_height= "100dip" android:layout_gravity= "Bottom|left" android:gravity= "Left|top" android:background= "#FF0000" android:text= "@ String/button " /></LinearLayout>
Note that TextView is not displayed in the center of the interface as we set the Android:layout_gravity property, and the button is not displayed at the bottom left of the interface. This is because we have set the Android:orientation property of LinearLayout to "vertical". For the linearlayout hypothesis setting android:orientation= "vertical", then the android:layout_gravity settings are only in the horizontal direction, such as TextView displayed in the horizontal center of the screen, The button appears at the far left of the horizontal direction, assuming that the android:orientation= "horizontal" is set, then the Android:layout_gravity property only takes effect in the vertical direction.
Android:layout_gravity and android:gravity attribute differences