Android Layout Relativelayout

Source: Internet
Author: User

The weight property of linear layout is convenient in equal scale distribution, but for complex interface, nesting multi-layer linearlayout layout will cause rendering to be slower, occupy more system resources, and using relativelayout, it may just need one layer to complete, You can set the display position of the component in the parent container or sibling component reference +margin +padding.

1. Container positioning

The parent container positioning property shows:

Brother Container Positioning Properties:

Example: Plum blossom layout

The implementation code is as follows:

<Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:id= "@+id/relativelayout1"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent" >            <!--This is in the middle of the container. -        <ImageViewAndroid:id= "@+id/img1"Android:layout_width= "80DP"Android:layout_height= "80DP"android:layout_centerinparent= "true"android:src= "@drawable/pic1"/>                <!--on the left of the middle picture -        <ImageViewAndroid:id= "@+id/img2"Android:layout_width= "80DP"Android:layout_height= "80DP"Android:layout_toleftof= "@id/img1"android:layout_centervertical= "true"android:src= "@drawable/pic2"/>                <!--to the right of the middle picture -        <ImageViewAndroid:id= "@+id/img3"Android:layout_width= "80DP"Android:layout_height= "80DP"Android:layout_torightof= "@id/img1"android:layout_centervertical= "true"android:src= "@drawable/pic3"/>                <!--on top of the middle picture -        <ImageViewAndroid:id= "@+id/img4"Android:layout_width= "80DP"Android:layout_height= "80DP"Android:layout_above= "@id/img1"Android:layout_centerhorizontal= "true"android:src= "@drawable/pic4"/>                <!--at the bottom of the middle picture -        <ImageViewAndroid:id= "@+id/img5"Android:layout_width= "80DP"Android:layout_height= "80DP"Android:layout_below= "@id/img1"Android:layout_centerhorizontal= "true"android:src= "@drawable/pic5"/>        </Relativelayout>

2. The difference between margin and padding

Margin represents the component's distance from the edge of the container, such as: MarginLeft = "5DP" for component distance to the left edge of container 5DP

Padding stands for padding, for example: TextView setting paddingleft = "5DP", which fills 5dp of space on the left side of the element in the component.

Margin is for the components in the container , and padding is for the elements in the component .

Android Layout Relativelayout

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.