In a Fragment, I am inflating a Layout with multiple child View. I need to get the dimensions (width and height) of one of them which is a custom view.
Inside the
this is a real pain especially because you expected with a name like onViewCreated in fragments lifecycle that the view is ready. for me get the fragment view itself like this:
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
getView()?.let{
it.doOnLayout{// do your UI work here }
}
}
this ensures the fragments getView has actually had one layout pass already.