【发布时间】:2013-07-03 16:14:44
【问题描述】:
有没有办法确定 GridView 的当前滚动偏移量或滚动位置?
View.getScrollY() // Underlying var is not updated during a scroll.
我已尝试设置 OnScrollListener,但 onScroll 回调的粒度不足以满足我的目的。
这是我尝试使用 OnScrollListener 确定滚动偏移量的方式。
private int getScrollY() {
int top = 0;
if (mGridView.getChildCount() > 0) {
final View firstView = mGridView.getChildAt(0);
top = firstView.getTop();
}
return top;
}
此代码的问题是向上滚动时返回的 y 偏移不准确;顶视图被回收,因此 y 偏移似乎跳跃;
有没有一种很好的方法来计算 GridView 的滚动偏移量?我似乎找不到好的解决方案。
【问题讨论】:
标签: android gridview scroll scroll-offset