first, the difference between several concepts:
Padding margin is the meaning of the margin, the key question is to understand what 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 a qualification to the view content. such as a button above the text. You can set the text in view on the left, right and so on. This is the property that did this.
Android:layout_gravity is used to set the position of a child view in this view relative to the parent view. For example, a button in the LinearLayout, you want to put the button on the left, on the right side of the position can be in LinearLayout through the property settings.
Copy Code code as follows:
<?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_content" android:gravity= "center_vertical" >
<imageview android:id= "@+id/ivlogo" android:layout_width= "50DP"
android:layout_height= "50DP" android:src= "@drawable/icon"
android:paddingleft= "5DP"/>
<relativelayout android:id= "@+id/rl_name"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content" android:gravity= "right"
android:padding= "10DP" >
<textview android:id= "@+id/tvapplicationname"
Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content"
Android:textsize= "16DP"/>
</RelativeLayout>
<relativelayout android:id= "@+id/rl_score"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content" android:gravity= "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 List_item layout in a ListView, displaying all the APK resources in a ListView, displaying icons, names, and ratings for each resource item. Add android:gravity= "center_vertical" to the outermost linearlayout of the ListItem, and the contents are centered vertically. Setting android:layout_width= "Fill_parent" in the Relativelayout with ID rl_score to fill the remaining space; android:gravity= "right" setting content relative to Rl_ Score right alignment, android:padding= "10DP" setting the margin of the content in Relativelayout relative to the relativelayout edge is 10DP.
Although this layout is simple, it is often used.