Last active
June 1, 2019 16:33
-
-
Save christianb/134c487444963a5fe49e68dfa0129432 to your computer and use it in GitHub Desktop.
LayoutInflater, Things to know about attachToRoot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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