【发布时间】:2020-08-05 17:22:07
【问题描述】:
在适配任何项目之前尝试获取适配器列表项目的像素高度
var item =
LayoutInflater.from(context).inflate(R.layout.adapter_item, null)
item.post {
System.out.println("height=$item.height")
}
上面 ^^^ 我对片段中引用和使用适配器的项目进行膨胀。然后我将高度打印为可运行对象,因此我知道高度不会过早调用并且不会为零。
Problem is runnable 不运行,item height 不打印。
我的问题是什么?谢谢
相关帖子 View's getWidth() and getHeight() returns 0
编辑
这个我也试过了,但是没有打印语句
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")
}
我认为问题可能与膨胀不在可见层次结构中的布局有关?
【问题讨论】:
标签: android android-layout android-fragments android-view