安卓在获得确切的ListView滚动位置 [英] Android getting exact scroll position in ListView

查看:87
本文介绍了安卓在获得确切的ListView滚动位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得在ListView滚动的准确,像素位置。 不,我不是指的是第一个可见的位置。

I'd like to get the exact, pixel position of the ListView scroll. And no, I am not referring to the first visible position.

有没有办法来实现这一目标?

Is there a way to achieve this?

推荐答案

好吧,我发现了一个解决方法,使用下面的code:

Okay, I found a workaround, using the following code:

View c = listview.getChildAt(0);
int scrolly = -c.getTop() + listview.getFirstVisiblePosition() * c.getHeight();

它的工作方式是采取实际的第一个可见的列表项的偏移量和计算是从视图的顶部有多远,以确定有多少我们是滚动到的说法,所以现在我们知道,我们可以使用常规getFirstVisiblePosition方法计算的其余部分。

The way it works is it takes the actual offset of the first visible list item and calculates how far it is from the top of the view to determine how much we are "scrolled into" the view, so now that we know that we can calculate the rest using the regular getFirstVisiblePosition method.

这篇关于安卓在获得确切的ListView滚动位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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