Trying to get pixel height of adapter list item before any items are adapted
var item =
LayoutInflater.from(context).inflate(R.layout.adapter_item, null)
item.post {
System.out.println("height=$item.height")
}
Above ^^^ I inflate an item in the fragment that references and uses the adapter. Then I print the height as a runnable so I know height is not called too early and will be non zero.
Problem is runnable does not run, and item height is not printed.
What is my issue? Thanks
relevant post View's getWidth() and getHeight() returns 0
edit
I've also tried this, but there is no print statement
item.viewTreeObserver.addOnGlobalLayoutListener {
//At this point the layout is complete and the
//dimensions of myView and any child views are known.
System.out.println("height=$item.height")
}
I think possibly the issue is related to inflating a layout which is not in a visible hierarchy?