更新时间:2023-09-18 21:28:34
你无法得到它,因为它确实不存在。 LayoutManager
只知道屏幕上的视图,它不知道之前的视图,它们的大小等等。
You cannot get it because it does not really exist. LayoutManager
only knows about the views on screen, it does not know the views before, what their size is etc.
使用滚动侦听器可以计算的数字是不可靠的,因为如果数据发生更改, RecyclerView
将执行新的布局计算,并且不会尝试重新计算实际偏移量(如果移动了视图,你将收到 onScroll(0,0)
。
The number you can count using the scroll listener is not reliable because if data changes, RecyclerView
will do a fresh layout calculation and will not try to re-calculate a real offset (you'll receive an onScroll(0, 0)
if views moved).
RecyclerView估算滚动条的这个值,您可以使用查看
类中的相同方法。
RecyclerView estimates this value for scrollbars, you can use the same methods from View
class.
computeHorizontalScrollExtent
computeHorizontalScrollRange
computeHorizontalScrollOffset
这些方法也有垂直对应方式。
These methods have their vertical counterparts as well.