Introduction to layoutinflator. Inflate() method in Android

Introduction to layoutinflator. Inflate() method in Android

Recently, I've been trying to understand the usage of the insert method of the layoutinflator object, and I've done an example today.

This is the itemgroup object.

The view referenced as include. The test code is as follows: (the inflator is an instance of the layoutinflator object. The method to obtain it is: inflator = layoutinflator. From (this). The other two methods are Baidu)

The test results are:

1. V1 and V3 have the same display effect in the activity. They are the original contents of itemgroup. V1 and V3 are r.layout.el_ The view object in include.

2. V2 and V4 have the same display effect in activity. Both itemgroup add r.layout.el_ After the content in include. Both V2 and V4 objects are added with r.layout.el_ Itemgroup of include.

The display effect of V2 and V4 in the activity is the same, indicating that the itemgroup has not changed!

The display effect of V2 and V4 in the activity is the same, indicating that the itemgroup has changed. Both of them are r.layout.el_ The contents in include are added to the view after itemgroup

The difference between merge and include is:

Include refers to an independent view, and the view referenced by merge must be placed in a ViewGroup. Examples are as follows:

R.layout.el_ The March reference must be:

Otherwise, an error is reported: < merge / > can be used only with a valid ViewGroup root and attachtoroot = true

In other words: merge is to reduce the root ViewGroup in include, so the margin of expand must be placed in ViewGroup.

There are also old people on the Internet talking about March and FrameLayout. In fact, I don't think there is a connection. It's r.layout.el_ If you don't add an element in the ViewGroup, the rules of the mage are the same as that of the FrameLayout.

If you have any questions, please leave a message or go to the community of this site for exchange and discussion. Thank you for reading. I hope it can help you. Thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>