Home > Mobile >  Why is inflate called an inflate in Android Studio (Kotlin)?
Why is inflate called an inflate in Android Studio (Kotlin)?

Time:09-23

I'm going through Android Studio(in Kotlin) codelabs created by Google. One thing gets me confused when they write something like: "you need to inflate the layout and bind individual views."

When I google what inflate means, I get answers like:

  • When you write an XML layout, it will be inflated by the Android OS which basically means that it will be rendered by creating view object in memory.
  • Inflating is the process of adding a view (. xml) to activity on runtime.
  • Layout inflater just reads the XML file and creates the specified views via reflection in top-down order

Okay, so the points above give slightly different answers. I understand from the explanations above that the .xml layout is rendered to create views. But then, why is it called inflating? Does the .xml inflate like a balloon into a view, and the balloon-like .xml is saved in memory somehow?

I can't find a good visual explanation, except code pieces on the internet. But code pieces, in this case, are not making this more sense to me.

Links to the bullet points:

CodePudding user response:

I guess the question is kind of subjective. But I would like to give my take on it. I believe it is indeed named after inflating balloons. A deflated balloon (xml file) sort of determines what an inflated balloon (an actual instance of a View) is supposed to look like. It is sort of like a blueprint. Inflating a balloon changes it from a unusable state to a usable one. Something similar happens here. But no one can really answer this question besides the people that created Android.

CodePudding user response:

It's just a name, inflating a layout is basically constructing a view out of the xml file. Why something is called the name that it is is something only the person who came up with it and named it can say for certain. Why is a fragment called fragment? More or less same thing here.

The only thing anyone can offer here is a guess and my guess would be that the way the layout is getting populated by the views made someone thing of a similarity to a balloon getting filled with air, that's just a guess though.

  • Related