简体   繁体   English

Android:在ScrollView完成滚动和弹回后检测?

[英]Android: Detect when ScrollView has finished scrolling and bouncing back?

I have a ScrollView which has two hidden images, one at the top and one at the bottom. 我有一个ScrollView,它有两个隐藏的图像,一个在顶部,一个在底部。 In between there is a bunch of visible content. 在两者之间有一堆可见的内容。

What I need to do is make these images hidden by default but when you scroll all the way up or all the way down you could see them as you're scrolling. 我需要做的是默认隐藏这些图像,但是当你向上滚动或完全向下滚动时,你可以在滚动时看到它们。 But then as soon as you stop scrolling it should bounce back to the visible area so that the hidden images aren't showing. 但是一旦你停止滚动它就应该反弹到可见区域,这样就不会显示隐藏的图像。

Basically I'm trying to imitate the bounce scrolling feature of the iphone UIScrollView. 基本上我试图模仿iphone UIScrollView的反弹滚动功能。

I have my ScrollView all setup and I do a scroll at the beginning so as to hide the top hidden image. 我有我的ScrollView所有设置,我在开头滚动,以隐藏顶部隐藏的图像。 Now all I need to do is detect when a scrolling has ended, figure out the Y position, and check whether a hidden image is shown. 现在我需要做的就是检测滚动何时结束,找出Y位置,并检查是否显示隐藏图像。 If it is, I would just programmatically scroll the view back so that the hidden image is hidden. 如果是,我将以编程方式向后滚动视图,以隐藏隐藏的图像。

I hope all that made sense. 我希望所有这些都是有道理的。

So anyways, I know how to programmatically scroll a ScrollView. 所以无论如何,我知道如何以编程方式滚动ScrollView。 Now what I need is some sort of callback to tell me when a ScrollView ended scrolling and also a way to get the ScrollView's current 'Y' position. 现在我需要的是某种回调告诉我什么时候ScrollView结束滚动,也是一种获取ScrollView当前'Y'位置的方法。 Are there any such methods I could use? 我可以使用任何这样的方法吗?

I looked through the ScrollView docs but nothing jumped out at me. 我查看了ScrollView文档,但没有任何内容跳出来。 I'm still not very familiar with the Android naming schemes so maybe I missed something obvious somewhere. 我仍然不太熟悉Android命名方案,所以也许我错过了一些明显的东西。

Anyways, any help would be appreciated here. 无论如何,任何帮助将在这里受到赞赏。 Cheers. 干杯。

You can use an OnTouchListener to detect when the user presses/releases the list. 您可以使用OnTouchListener来检测用户何时按下/释放列表。

You can also use the onScrollStateChanged method of the OnScrollListener class (most likely in conjunction with a touch listener) to detect changes in the SCROLL_STATE - when the list has stopped scrolling the state will change from a state that is not SCROLL_STATE_IDLE to SCROLL_STATE_IDLE . 您还可以使用OnScrollListener类的onScrollStateChanged方法(最有可能与触摸侦听器一起)来检测SCROLL_STATE更改 - 当列表停止滚动时,状态将从不是 SCROLL_STATE_IDLE的状态更改为SCROLL_STATE_IDLE

Alternatively if you are using 2.3 or above you can use an OverScroller to get the desired effect (see Modifying Android OverScroll for how to change the over scroll effect to an iPhone like one). 或者,如果您使用的是2.3或更高版本,则可以使用OverScroller来获得所需的效果(请参阅修改Android OverScroll以了解如何将过度滚动效果更改为类似iPhone的效果)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM