The error message returned when setting wrap_content in RelativeLayout is invalid,

Source: Internet
Author: User

The error message returned when setting wrap_content in RelativeLayout is invalid,

Respect labor results, reprinted please indicate the source: http://www.cnblogs.com/tangZH/p/8419053.html

 

During the project, I encountered a strange phenomenon. I set the width of RelativeLayout to wrap_content, and the components in RelativeLayout also set a fixed size, however, the RelativeLayout width is still full throughout the screen.

 

Why ??? Face-to-face

Baidu later found that the official documentation has explained:

A Layout where the positions of the children can be described in relation to each other or to the parent.Note that you cannot have a circular dependency between the size of the RelativeLayout and the position of its children. for example, you cannot have a RelativeLayout whose height is set to WRAP_CONTENT and a child set to ALIGN_PARENT_BOTTOM.

 

It means:Circular dependency cannot exist between the RelativeLayout size and the sub-level location. For example, you cannot set the RelativeLayout height to WRAP_CONTENT, and set the child to ALIGN_PARENT_BOTTOM.

 

The two situations I have encountered are as follows:

1. Set the RelativeLayout width to wrap_content, and the child component

Android: layout_alignParentEnd = "true"

As a result, the screen is filled with RelativeLayout width.

 

2. Set the height of RelativeLayout to wrap_content, and the child component

ALIGN_PARENT_BOTTOM

As a result, the screen is filled with RelativeLayout height.

 

Finally, I changed my mind to LinearLayout 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.