Http://www.cnblogs.com/lijunamneg/archive/2013/01/10/2855446.html
Make a clear distinction between several concepts first:
Padding margin is the meaning of margin, the key question to understand what is the relative margin.
Padding is the margin of the control's content relative to the edge of the control.
Margin is the margin of the control's edge relative to the parent space.
The Android:gravity property is the qualification for the view content.
For example, a button above the text. You can set the text on the left side of the view, on the right, and so on. This property is done with this.
Android:layout_gravity is used to set the position of the child view in the view relative to the parent view.
For example, a button in the LinearLayout, you want to put the button on the left, right, etc. can be set in the LinearLayout through this property.
Below you see the layout file and
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "android:orientation=" horizontal "android:layout_width=" Fill_parent "android:layout_height=" Wrap_con Tent "android:gravity=" center_vertical "> <imageview android:id=" @+id/ivlogo "android:layou T_width= "50DP" android:layout_height= "50DP" android:src= "@drawable/icon" android:paddingleft= "5d P "/> <relativelayout android:id=" @+id/rl_name "android:layout_width=" Wrap_content " android:layout_height= "Wrap_content" android:gravity= "right" android:padding= "10DP" > <tex TView android:id= "@+id/tvapplicationname" android:layout_width= "Wrap_content" Android : layout_height= "wrap_content" android:textsize= "16DP"/> </RelativeLayout> <relativel Ayout android:id= "@+Id/rl_score "android:layout_width=" fill_parent "android:layout_height=" Wrap_content "Android:gra Vity= "Right" android:padding= "10DP" > <textview android:id= "@+id/tvrating" Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:text= "5.0"/> ; <ratingbar android:id= "@+id/ratingbar" android:layout_width= "Wrap_content" Android : layout_height= "Wrap_content" android:numstars= "5" style= "? Android:attr/ratingbarstylesmall" android:layout_below= "@id/tvrating"/> </RelativeLayout> </LinearLayout>
The above layout file is a ListView List_item layout that displays all the APK resources in a ListView, each resource item displays icons, names and ratings.
Add android:gravity= "center_vertical" to the outermost linearlayout of ListItem, and set content to center vertically.
Set the Android:layout_width= "Fill_parent" in the Relativelayout with ID rl_score to fill the remaining space;
Android:gravity= "Right" setting content is aligned to Rl_score.
android:padding= "10DP" sets the margin of the relativelayout content relative to the relativelayout edge to 10DP.
Although this layout is simple, it is often used.
Precise layout with LinearLayout and relativelayout (a frequently used layout)