In wirelessly these two properties are often used, specifically to summarize:
Android:layout_gravity:XML inside the hint is this, standard gravity constant, the child supplies to its parent. [flag], I roughly translate a constant that a child view provides to the parent view as the specified location.
Android:gravity:Specifies How to align the text by the view's x-and/or y-axis when the text is smaller than the view. [flag], the text is a bit long, roughly meaning that this property is a property that determines how to determine the content of the view
Android:layout_gravity can only be used with LinearLayout, in LinearLayout, specifies that the layout is valid, that is, when the property is developed for a control or layout, the parent layout must be linearlayout to be specified, otherwise there is no , there is no hint in XML, in particular, when linearlayout specifies android:orientation= "vertical", android:layout_gravity is only valid in horizontal direction; when Android:o When rientation= "Horizontal", the property is only valid in the vertical direction.
Note that if the child view is not centered, it may be because the Layout_width or Layout_height property is Fill_parent, and changed to Wrap_content
1 linearlayout nested relativelayout: valid, which in turn invalidates the property.2 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:layout_width= "Fill_parent"4 Android:layout_height= "Fill_parent"5 android:orientation= "vertical" >6 7 <Button8 Android:layout_width= "Wrap_content"9 Android:layout_height= "Wrap_content"Ten Android:text= "AAA" /> One A <Button - Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" the Android:text= "AAA" /> - - <Button - Android:layout_width= "Wrap_content" + Android:layout_height= "Wrap_content" - Android:text= "AAA" /> + A <Relativelayout at android:gravity= "Center" - Android:layout_width= "Fill_parent" - Android:layout_height= "Fill_parent" - android:layout_gravity= "Center_vertical" > - - in <Button - Android:id= "@+id/button1" to Android:layout_width= "Wrap_content" + Android:layout_height= "Wrap_content" - Android:text= "button" /> the </Relativelayout> * $ </LinearLayout>
1 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Android:layout_width= "Fill_parent"3 Android:layout_height= "Fill_parent"4 android:orientation= "Horizontal" >5 6 <Button7 Android:layout_width= "Wrap_content"8 Android:layout_height= "Wrap_content"9 Android:text= "AAA" />Ten One <LinearLayout A android:layout_gravity= "Center_vertical" - Android:layout_width= "Fill_parent" - Android:layout_height= "Wrap_content" > the - <Button - Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" + Android:text= "AAA" /> - </LinearLayout> + A </LinearLayout>
Android:layout_gravity and Android:gravity