Android的ListView的当前滚动位置Y-像素 [英] Android ListView current scroll location Y pixels

查看:569
本文介绍了Android的ListView的当前滚动位置Y-像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图发现当列表视图(通过第一项的一半)滚动超出像素某些固定的阈值。不幸的是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();

这篇关于Android的ListView的当前滚动位置Y-像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆