AmirG AmirG - 1 month ago 10
Android Question

Does Android's databinding layout tag adds another viewgroup to current layout?

I want to know if the root tag for databinding adds internally another ViewGroug to current layout.

Sometimes some views don't need any model or data for binding but i kind of like having access to the view through binding like biding.currenView instead of going for findViewById( But i'm not sure if with adding the layout tag i'm adding an unnecessary view group

Answer Source

No, the <layout> root element is not a ViewGroup. Basically, they needed some way to add more information to the resource that wasn't tied to any View/ViewGroup, so they created this <layout> wrapper.

The actual layout resource that goes into the APK does not have the <layout> starting/ending tags or the contents of the <data> element. In fact, in the project that I'm examining right now, they literally replace those lines with newlines, so there is a big blank space in the layout file. You can see them in app/build/intermediates/data-binding-layout-out/ (for an app module), if you're interested.