First, let's clarify the differences between several concepts:
Padding margin: it is the meaning of margins. The key issue is to understand what the margins are.
Padding: the margin between the content of the control and the edge of the control.
Margin: margin of the control edge relative to the parent space
Android: gravityIs the limitation of the View content.
For example, the text above a button. You can set the text to the left and right of the view. This attribute is used.
Android: layout_gravityIs used to set the position of the child view in the view relative to the parent view.
For example, if a button is in linearlayout, you can set it in linearlayout by placing it on the left and right.
XML
Layout File
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: Orientation = "horizontal" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: gravity = "center_vertical"> </P> <p> <imageview Android: id = "@ + ID/ivlogo" <br/> Android: layout_width = "50dp" <br/> Android: layout_height = "50dp" <br/> Android: src = "@ drawable/icon" <br/> Android: paddin Gleft = "5dp"/> </P> <p> <relativelayout Android: Id = "@ + ID/rl_name" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: gravity = "right" <br/> Android: padding = "10dp"> </P> <p> <textview Android: Id = "@ + ID/tvapplicationname" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: textsize = "16dp"/> <br/> </relativelayout> </P> <p> <Relativelayout Android: Id = "@ + ID/rl_score" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: gravity = "right" <br/> Android: padding = "10dp"> </P> <p> <textview Android: id = "@ + ID/tvrating" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: TEXT = "5.0"/> </P> <p> <ratingbar Android: Id = "@ + ID/ratingbar" <br/> Android: Layout _ Width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: numstars = "5" <br/> style = "? Android: ATTR/ratingbarstylesmall "<br/> Android: layout_below = "@ ID/tvrating"/> <br/> </relativelayout> </P> <p> </linearlayout> <br/>
Layout File above
The above layout file is the list_item layout in a listview. All APK resources are displayed in a listview, and icons, names, and scores are displayed for each resource item.
AddAndroid: gravity = "center_vertical"To set the vertical center display of the content.
InRl_scoreSet in relativelayoutAndroid: layout_width = "fill_parent"To fill the remaining space;
Android: gravity = "right"Set content relativeRl_scoreRight alignment;
Android: padding = "10dp"Set the margin of content in relativelayout to 10dp relative to the edge of relativelayout.
This layout is simple but often used.