Android 在 ListView 中获取准确的滚动位置 [英] Android getting exact scroll position in ListView

查看:20
本文介绍了Android 在 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?

推荐答案

好的,我找到了一个解决方法,使用以下代码:

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.

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

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