android - 如何得到recyclerview item的宽度?

【字号: 日期:2022-12-16浏览:22作者:雯心

问题描述

问题解答

回答1:

你获取到RecyclerView item的视图对象,直接调用getWidth()自然就获取到了它的宽度。

回答2:

recyclerView.getLayoutManager().getChildAt(0).getHeight();得到指定postition的item

回答3:

这个问题得分情况回答了:

如果视图准备好(即视图可见), 找到ItemView并直接调用getWidth()

如果视图未准备好, 则需要借助View#post(Runnable)来实现, ----在run()中调用getWidth()

相关文章: