Android Layoutinflate.inflate method, Removeview () Error resolution

Source: Internet
Author: User

Error:

The specified child already has a parent. You must call Removeview (). Answer:This error is straightforward, you Viewgroup.addview (Childview), Childview already has a Father view. The reason for the error is many, I mainly talk about Mlayoutinflater.inflate (ID, Rootview, false); This error is caused. (There are two kinds of this method, one is 2 parameters and one is 3 parameters).
2 parameters:First parameter: The XML file ID of layout; The second parameter: the root view in the XML file, which is the parent viewto which the child view is added. that is, the parent view layoutA: if Rootview is not NULL, the method return value is Rootview (Rootview has added a child view of the XML representation); b: If Rootview is empty, the method returns directly child view ( xml the child view of the representative); , ( So use mlayoutinflater.inflate (ID, rootview); The return is actually Rootview, And Rootview must have a parent layout (Decorateview, System-generated). So Rootview.addview (mlayoutinflater.inflate (ID, Rootview)). is equivalent to Rootview.addview (Rootview). So it's wrong.
3 parameters:the question is, how to fix the B case, preserving both the Layoutparams attribute in the XML file and the way to return to the parent view. two steps Rootview! = NULL (is the object arbitrarily), the third parameter = = false; mlayoutinflater.inflate (ID, Rootview, false), so that you can attach root view and keep layoutparams.

Android Layoutinflate.inflate method, 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.