Skip to content

Instantly share code, notes, and snippets.

@christianb
Last active June 1, 2019 16:33
Show Gist options
  • Save christianb/134c487444963a5fe49e68dfa0129432 to your computer and use it in GitHub Desktop.
Save christianb/134c487444963a5fe49e68dfa0129432 to your computer and use it in GitHub Desktop.
LayoutInflater, Things to know about attachToRoot
// Something you don't know about Android's LayoutInflater
// by Abhishek Jangra
// https://medium.com/@iabhishek1041/something-you-dont-know-about-android-layoutinflater-6de7709289ac
val inflater: LayoutInflater = LayoutInflater.from(this)
// When attachToRoot is true, the generated view from the a_view XML will automatically attached to the rootView,
// but it will not return the inflated view but the rootView itself.
val rootViewReference = inflater.inflate(R.layout.a_view, rootView, attachToRoot = true)
// this will not attach the view to the rootView. The returned reference is the inflated aView from XML.
val aView = inflater.inflate(R.layout.a_view, rootView, attachToRoot = false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment