As per my understanding,
LayoutInflater.inflate(resource, root, attachToRoot):- It's job is JUST to convert the XML to the Views object.
My question is, since inflate() is not concerned with root
parameter if we are passing attachToRoot = false
, then can we use LayoutInflater.inflate(R.layout.my_custom_view, null, false)
without any blunder?
The reasoning behind the above is, getView(..)
is only responsible for returning the dynamic view which is constructed according to the position, it isn't responsible for attaching this constructed View to the parent ViewGroup.
CodePudding user response:
The root view can also affect the layout. The inflated view can be sized and positioned relative to its parent (for example, match_parent
size param), and the root view parameter works as the parent for layout purposes even if the view doesn't (yet) get added to it.