Android linearlayout and relativelayout implement precise Layout

Source: Internet
Author: User
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.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.