Android Layoutinflate.inflate Method Specific explanation, Removeview () Error resolution

Source: Internet
Author: User

Error:

The specified child already has a parent. You must call Removeview (). Answer:This error is very straightforward, you Viewgroup.addview (Childview), Childview already has a Father view. The reason for the error is very much, I mainly talk about the mlayoutinflater.inflate (ID, Rootview, false), caused by this error. (This method has two types.) One is 2, and the other is 3 parameters.
2 parameters:First parameter: The XML file ID for layout. second parameter: The root view in the XML file as the parent viewto which the child view is added. that is, the parent view layoutA: assuming Rootview is not NULL, the method return value is Rootview (Rootview has been added to the XML representation of the Child view). B: Assuming that Rootview is empty, the method returns directlyChild View(XML represents a child view). Then the layoutparams in the XML file is invalid . (Because Layoutparams is used for the parent view of the view represented by the XML.

The size of the quantum view is measured in the onmeasure () of the parent view based on whether Layoutparams is Match_parent or wrap_content. Assuming no parent view is not required ) the mlayoutinflater.inflate (ID, rootview) is used. The return is actually Rootview, and Rootview must already have the parent layout (Decorateview, System-generated). So Rootview.addview (mlayoutinflater.inflate (ID, Rootview)). Equivalent to Rootview.addview ( Rootview). So wrong.


3 references: Here comes the question. How to fix B case. The Layoutparams attribute in the XML file is preserved, and there is no way to return to the parent view. two steps Rootview! = NULL (is that object arbitrarily), the third parameter = = FALSE; Mlayoutinflater.inflate (ID, Rootview, False), so that you can not attach root view. And keep layoutparams.

Android Layoutinflate.inflate Method specific explanation, Removeview () Error resolution

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.