RealtiveLayout of Android UI (relative layout)

Source: Internet
Author: User
Tags xml attribute

RealtiveLayout of Android UI (relative layout)
RealtiveLayout of Android UI (relative layout)

Note: RealtiveLayout is the most commonly used layout manager in android Development (more frequently than LinearLayout ), the positions of child components in the layout are always determined by other child components and RealtiveLayout layout. The biggest advantage of this is that it is more flexible and flexible. You can design a more cool and complex interface, and you can drag and drop the interface in the IDE to design the layout of the interface.
Note: The android: layout_gravity attribute cannot be set for RealtiveLayout sub-components.

In RealtiveLayout, there are many attributes to be concerned with, which can be divided into three categories:

1 android: ignoreGravity

Method: setIgnoreGravity (int)
Description: sets child components that are not affected by the gravity attribute. Like other la S, Realtivelayout can also use the android: gravity attribute to set the placement of its sub-components. However, RealtiveLayout requires more complex la S, therefore, it is difficult to set a unified placement method for all components to meet some special requirements in actual development. Therefore, this family of elements is used for special ignoring.
Example:


      
       
    
   
  

VcHLsry + logs/qsq8sNq3xaGjPC9wPg0KPGgzIGlkPQ = "2-only xml attributes that can be set to truefalse"> 2. xml attributes that can only be set to true or false

Note: This type of attribute is mainly used to make up for the regret that the RealtiveLayout sub-component cannot set the layout_gravity attribute. You can directly specify the placement location for the sub-component.

The following table lists the attributes of these types:

Attribute name Function Description
Android: layout_centerHoriazontal Controls whether the child component is horizontally centered relative to the parent container
Android: layout_centerVertical Determines whether the child component is perpendicular to the parent container
Android: layout_centerInParent Determines whether the child component is centered relative to the parent container.
Android: layout_alignParentBottom Determines whether the child component is aligned with the bottom of the parent container.
Android: layout_alignParentTop Determines whether the child component is aligned with the parent container top.
Android: layout_alignParentLeft Determines whether the child component is aligned with the left side of the parent container.
Android: layout_alignParentRight Determines whether the child component is aligned with the right side of the parent container.
Android: layout_alignParentEnd Determines whether the child component is aligned with the parent container end (upper right corner)
Android: layout_alignParentStart Determines whether the child component is aligned with the parent container (upper left corner)

However, if Conflicting attributes (such as layout_alignParentLeft and layout_alignParentRight) are used at the same time, they will produce some odd results, therefore, we do not recommend that you use Conflicting attributes at the same time.


      
   
  


The system will try to adapt to all attributes, resulting in components being stretched to a strange look.

3. You can only set the xml Attribute for other UI component IDs.

Note: These attributes are the core attributes of RealtiveLayout. They are used to determine the relationship between each child component in the layout.
The following table lists the attributes of these types:

Attribute name Function Description
Android: layout_toRightOf Control the sub-component to the right of the component specified by ID
Android: layout_toLeftOf Control the sub-component to the left of the component specified by ID
Android: layout_abve Control the sub-component to be located above the component specified by ID
Android: layout_below Controls the sub-component to be located below the component specified by the ID
Android: layout_alignTop Controls the alignment between the top of the component and the upper boundary of the component specified by the ID.
Android: layout_alignBottom Controls the bottom-layer alignment of the component with the specified ID.
Android: layout_alignLeft Controls the left-side alignment of the component with the ID
Android: layout_alignRight Controls the right side of the component to align with the right border of the component specified by the ID
Android: layout_alignStart Controls the starting position of the component to align with the starting position of the component specified by the ID (upper left corner)
Android: layout_alignEnd Controls the end position of the component to align with the end position of the component specified by the ID (upper right corner)

In addition, you can use margin or padding to slightly adjust the components, as shown below:

 
      
       
        
     
    
   
  

 

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.