我试图发现当列表视图(通过第一项的一半)滚动超出像素某些固定的阈值。不幸的是ListView的getScrollY()似乎总是返回0 instad滚动位置的。有什么办法用像素来获得实际的滚动位置?
I'm trying to detect when a list view is scrolled beyond certain fixed threshold in pixels (half way through the first item). Unfortunately listview's getScrollY() seems to always return 0 instad of the scroll position. Is there any way to get the actual scroll location by pixel?
这里的code我尝试使用,但因为说它只返回0。
Here's the code I tried to use but as said it only returns 0.
getListView().setOnScrollListener(new AbsListView.OnScrollListener() {
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
Log.d("scroll", "scroll: " + getListView().getScrollY());
}
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState == 0)
Log.d("scroll", "scrolling stopped");
}
});
有为Y涡旋盘为一个ListView在机器人仅仅是因为内容的总高度是未知的概念。所显示的内容的唯一的高度是已知的。
There is no notion of Y scroll for a ListView in Android simply because the total height of the content is unknown. Only the height of the displayed content is known.
不过,可以获取当前位置/使用下面的技巧可见项目的ÿ滚动:
However it is possible to get the current position/Y scroll of a visible item using the following hack:
getListView().getChildAt(0).getTop();