Realtivelayout of Android UI (relative layout)

Source: Internet
Author: User
Tags xml attribute

Description: Realtivelayout is the most commonly used layout manager in Android Development (more commonly than linearlayout), where sub-components within a layout are always determined by the other subcomponents and the realtivelayout layout itself. The biggest benefit is more freedom and flexibility, you can design a more cool complex interface, but also in the IDE through the direct drag-and-drop interface layout design.
Note: Realtivelayout subcomponents cannot set the Android:layout_gravity property.

There are more attributes to be concerned about in realtivelayout, which can be divided into three categories:

1 android:ignoregravity

Corresponding method: setignoregravity (int)
Description: Sets the subcomponents that are not affected by the gravity property. As with other layouts, realtivelayout can also use the Android:gravity property to set the placement of its subcomponents, but realtivelayout need to implement a more complex layout, So for all components to set a unified placement method is difficult to meet the actual development of some special needs, so there is this zodiac to do special neglect.
Give me a chestnut:

<RelativeLayout    android:gravity="bottom"    android:ignoreGravity="@id/view1"    android:layout_width="fill_parent"    android:layout_height="fill_parent">    <ImageView        android:id="@+id/view1"        android:layout_width="100dp"        android:layout_height="100dp"        android:scaleType="fitXY"        android:src="@drawable/muogu" />    <ImageView        android:layout_width="100dp"        android:layout_height="100dp"        android:scaleType="fitXY"        android:src="@drawable/nailiu16" /></RelativeLayout>

As you can see, because gravity is set to bottom in Realtivelayout, the second imageview is placed at the bottom of the layout, and the ignoregravity set in View1 is still in its own right, starting from the upper left corner.

2 XML attribute can only be set to True, False

Note: This type of attribute is primarily intended to compensate for the regret that the Realtivelayout subcomponent cannot set the Layout_gravity property, and can be assigned to the subassembly directly.

The following is the property sheet for this type of attribute:

property name feature description
android:layout_center Horiazontal Controls whether the subassembly is centered horizontally relative to the parent container
android:layout_centervertical control the subassembly is Center vertically relative to parent container
android:layout_centerinparent Controls whether the subassembly is centered relative to the parent container
Android:layout_alignparentbottom controls whether this subassembly is aligned with the bottom of the parent container
android:layout_alignparenttop Controls whether this subassembly aligns with the top of the parent container
android:layout_alignparentleft Controls whether this subassembly aligns with the left of the parent container
android:layout_alignparentright Controls whether the subassembly is aligned to the right end of the parent container
android:layout_alignparentend Controls whether the subassembly is aligned to the end of the parent container (in most cases with alignparentright an effect)
Android:layout_alignparentstart Controls whether the subassembly starts aligning with the parent container (in most cases with an effect of alignparentleft)

It is important to note that these zodiac can be used at the same time, but if conflicting attributes (such as Layout_alignparentleft and layout_alignparentright) are used at the same time, there are some more bizarre effects, It is therefore not recommended to use conflicting properties at the same time.

<RelativeLayout    android:layout_width="fill_parent"    android:layout_height="fill_parent">    <ImageView        android:id="@+id/view1"        android:layout_width="100dp"        android:layout_height="100dp"        android:scaleType="fitXY"        android:layout_alignParentLeft="true"        android:layout_alignParentRight="true"        android:layout_centerVertical="true"        android:layout_centerHorizontal="true"        android:src="@drawable/muogu" /></RelativeLayout>


The system will try to adapt to all of the properties, causing the component to be stretched to a strange look.

3 XML attributes that can be set to other UI component IDs only

Description: These zodiac are the core attributes of Realtivelayout, which are the properties that determine the layout of each sub-component.
The following is the property sheet for this type of attribute:

Property name function Description
Android:layout_torightof Controls this subassembly on the right side of the ID specified component
Android:layout_toleftof Controls this subassembly at the left of the ID specified component
Android:layout_above Controls the sub-component above the ID specified component
Android:layout_below Controls the sub-component below the ID specified component
Android:layout_aligntop Controls the top edge of the component with the ID specified in the upper bounds of the component
Android:layout_alignbottom Controls the bottom boundary of the end component from the ID specified component
Android:layout_alignleft Controls the left edge of the component with the ID specified component
Android:layout_alignright Controls the right edge of the component with the ID specified component
Android:layout_alignstart Controls the starting position of the component aligned with the starting position of the ID specified component (in most cases the same as the Layout_alignleft effect)
Android:layout_alignend Controls where the end position of the component is aligned with the end position of the specified component of the ID (in most cases the same as the Layout_alignright effect)

You can also use margin or padding to make minor adjustments to the components as follows:

 <RelativeLayout    android:layout_width="fill_parent"    android:layout_height="fill_parent">    <ImageView        android:id="@+id/view1"        android:layout_width="100dp"        android:layout_height="100dp"        android:layout_alignParentEnd="true"        android:src="@drawable/nailiu16"        android:scaleType="fitXY" />    <ImageView        android:id="@+id/view2"        android:layout_width="100dp"        android:layout_height="100dp"        android:src="@drawable/muogu"        android:scaleType="fitXY"        android:layout_alignParentRight="true"        android:layout_below="@+id/view1" />    <ImageView        android:layout_width="100dp"        android:layout_height="100dp"        android:src="@drawable/muogu"        android:scaleType="fitXY"        android:layout_margin="50dp"        android:layout_alignParentRight="true"        android:layout_alignBottom="@+id/view2" /></RelativeLayout>

Attached: Citation statement

"Crazy Android Handout (second edition)" Li Gang "2.2.4 relative layout" Electronic industry Press

Realtivelayout of Android UI (relative layout)

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.