Android的ListView控件:获得反弹时的距离控件、距离、Android、ListView

2023-09-07 23:06:33 作者:一身仙女味

反正是有确定一个用户拥有的像素的确切数量 overscrolled 通过在Android的ListView?当用户试图过去的第一个列表项滚动,在反弹时/反弹动画踢,我需要检测的反弹时的距离。基本上,我会做一些空间,像动画倍,类似清除应用上的 iPhone

Is there anyway to determine the exact number of pixels that a user has overscrolled by in an Android ListView? When the user tries to scroll up past the first list item, and the overscroll/bounce animation kicks in, I need to detect the overscroll distance. Basically I'm going to do something in that space, like a fold in animation, similar to the Clear app on iPhone.

我已经打过电话 getScrollY()共达()在我的ListView,它的项目(使用 getChildAt(0).getTop ),但一切都返回0。对于我的参考列表项都是相同的高度。

I've tried calling getScrollY() and getTop() on my ListView, and its items (using getChildAt(0).getTop), but everything returns 0. For reference my list items are all the same height.

我也尝试添加 onScrollListener 列表视图,只计算原始Y位置之间的差异在 ACTION_DOWN ,并在 ACTION_MOVE 的Y位置,但似乎在列表视图滚动以较慢的速度。

I've also tried adding an onScrollListener to the listview and just calculating the difference between the original Y pos on ACTION_DOWN, and the Y pos on ACTION_MOVE, but it seems that the listview scrolls at a slower velocity.

任何帮助将是巨大的。

Any help would be great.

推荐答案

挖得多,甚至更多的挫折后,答案似乎是,你不能。什么是更可气的是,我看了一下Android的来源$ C ​​$ C 并可以看到,code我需要的是很好地全部隐藏在AbsListView的内心gubbings。但一切都没有失去。看来你可以使用AbsListView为指导构建自己的观点,而你需要在它里面的东西。它比我想要更多冗长,但就这样吧。我还发现一个不错的关于如何建立你自己的看法,在其中你可以做任何你想要的教程。

After much digging, and even more frustration, the answer seems to be that you can't. What's even more annoying is that I took a look at the Android source code and can see that the code I need is all nicely hidden away in the AbsListView's inner gubbings. But all is not lost. Seems that you can build your own view using the AbsListView as a guide, and do what you need inside it. It's more longwinded than I wanted, but so be it. I also found a nice tutorial on how to build your own view, in which you can do whatever you want.

修改

我终于有一个演示和Github上运行。如果你有兴趣,你可以在这里找到它 。当您从顶部向下拖动一个新的视图会旋转,如果你放手或滚动视图会旋转的。

I finally have a demo up and running on Github. If you're interested you can find it here. When you pull down from the top a new view will rotate in, if you let go or scroll up the view will rotate out.