[Android Layout Learning Series]
1.Android Layout Learning--layout (layout) detailed one
2.Android Layout Learning--layout (layout) detailed two (common layout and layout parameters)
The Layout_weight attribute of the--linearlayout of 3.Android layout learning
The function and baseline of--linearlayout attribute baselinealigned in 4.Android layout learning
1. What are the differences?
Android:gravity:
defines the contents of an object in an X, Y axis, within its own bounds, and how it should be placed.
android:layout_gravity :
The standard gravity constant, which is the parent component that the child component provides to it. Defines how the child view should be placed in the X, y direction in the closed layout .
If you need to set multiple gravity values, use the ' | ' Symbol Delimited. Such as
Android:layout_gravity= "Right|bottom"
Android:gravity= "Right|bottom"
2. Differences
Look at the name to see some differences: android:layout_gravity and layout.
Android:gravity sets the gravity of the view's contents.
Android:layout_gravity Sets the view or layout of the gravity in its parent layout.
3.Demo
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 android:orientation= "vertical"4 Android:layout_width= "Match_parent"5 Android:layout_height= "Match_parent">6 7 <LinearLayout8 Android:id= "@+id/linearlayout"9 Android:layout_width= "Match_parent"Ten Android:layout_height= "150DP" One android:orientation= "vertical"> A <TextView - Android:layout_width= "Match_parent" - Android:layout_height= "50DP" the Android:text= "Android:gravity is used to set the alignment of content in view relative to the view component"/> - <TextView - Android:layout_width= "Match_parent" - Android:layout_height= "50DP" + Android:text= "Android:gravity=center" - Android:background= "#ff0000" + android:gravity= "Center"/> A <TextView at Android:layout_width= "Match_parent" - Android:layout_height= "50DP" - Android:text= "Android:gravity=right|bottom" - Android:background= "#00ff00" - android:gravity= "Right|bottom" - /> in </LinearLayout> - <TextView to Android:id= "@+id/textview" + Android:layout_width= "Match_parent" - Android:layout_height= "50DP" the Android:layout_below= "@id/linearlayout" * Android:text= "Android:layout_gravity is used to set the alignment of the view component with respect to the container"/> $ <LinearLayoutPanax Notoginseng Android:id= "@+id/linearlayout1" - Android:layout_width= "Match_parent" the Android:layout_height= "100DP" + Android:layout_below= "@id/textview" A android:orientation= "vertical"> the <TextView + Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" $ android:layout_gravity= "Left" $ Android:text= "Android:layout_gravity=left" - Android:background= "#ff0000" - /> the <TextView - Android:layout_width= "Wrap_content"Wuyi Android:layout_height= "Wrap_content" the android:layout_gravity= "Right" - Android:text= "Android:layout_gravity=right" Wu Android:background= "#00ff00" - /> About </LinearLayout> $ <LinearLayout - Android:id= "@+id/linearlayout2" - Android:layout_width= "Match_parent" - Android:layout_height= "100DP" A Android:layout_below= "@id/linearlayout1" + android:orientation= "Horizontal"> the <TextView - Android:layout_width= "Wrap_content" $ Android:layout_height= "Wrap_content" the android:layout_gravity= "Top" the Android:text= "Android:layout_gravity=top" the Android:background= "#ff0000" the /> - <TextView in Android:layout_width= "Wrap_content" the Android:layout_height= "Wrap_content" the android:layout_gravity= "Bottom" About Android:text= "Android:layout_gravity=bottom" the Android:background= "#00ff00" the /> the </LinearLayout> + </Relativelayout>
Effect:
Android Layout Learn the difference between--android:gravity and android:layout_gravity