I'm a new Android developer. I have tried to understand the use of Layout inflator from the documentation but have not been able to understand. what is the use of layout inflator in android?
What are the situations when one would have to use it?
See this
Basically think of your xml flat files as a balloon without air and, what the LayoutInflator does is blows it up (or inflates) into a full sized balloon a.k.a. your Views and, or View groups. So flat file gets inflated into view. (feel free to critique the metaphor but, that is how I think of it anyway) and as far as usage goes check this article out. The author talks about manually inflation of objects.
Internally an xml parser, that is mapped to a cached subset of the Android.Resource, looks for applicable xml that is recognized as a view instantiates them and adds them to the view group.
From that internally rInflate
in LayoutInflator parses the xml file and adds the result to the parent view. Look for the overload with the specific signature
void rInflate(XmlPullParser parser, View parent, final AttributeSet attrs, boolean finishInflate)
In the comments ofLayoutInflater
For performance
* reasons, view inflation relies heavily on pre-processing of XML files
* that is done at build time. Therefore, it is not currently possible to
* use LayoutInflater with an XmlPullParser over a plain XML file at runtime.
So with that we can infer that the xml from the file is cached at compile time to cut the amount of processing required to handle parsing the file.
XmlResourceParser loadXmlResourceParser(String file, int id, int assetCookie, String type)
in the file
Resources.java.I hope this clears things up a bit more.
_ _ _ _ _ _ _ _ _ _ _ _
| |
| _____________ |
| Name |_____________|--|-----<2 objects(TextView,EditText)>
| _____________ |
| Age |_____________|--|-----<2 objects(TextView,EditText)>
| _____________ |
| Phone|_____________|--|-----<2 objects(TextView,EditText)>
| |
| |
| |
| |
| ------ |
| |BUTTON| -------|-----<1 objects(ButtonView)>
| ------ |
| |
-----------------------
We can clearly see from the above figure,
What are these complex actions ?
instantiation
is made here.Inflator service
thse object creation is done & this process is called layout Inflation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With