在滚动的中间停止scrollView

Dee*_*ati 11 android scrollview onscroll onfling

我有一个包含大量内容的滚动视图.现在,当用户进行投掷或向下滚动时,我希望滚动视图停在特定的视图位置,我正在做一些动画,然后用户可以再次投掷或向下滚动.

我已尝试禁用此处提到的scrollview 但它只在scrollview完全停止并且无法在fling中间停止时禁用.

有什么办法可以在达到某个视图位置或某个y值时停止滚动视图的投掷?

Yay*_*ano 10

我的解决方案遇到了同样的问题.

listView.smoothScrollBy(0,0)
Run Code Online (Sandbox Code Playgroud)

这将停止滚动.


Pet*_*r F 7

要在特定点停止投掷,只需调用

fling(0)
Run Code Online (Sandbox Code Playgroud)

如果您只关心投掷,我认为这是最合乎逻辑的方法,因为velosityY设置为 0,因此投掷会立即停止。

这是 fling 方法的 javadoc:

/**
 * Fling the scroll view
 *
 * @param velocityY The initial velocity in the Y direction. Positive
 *                  numbers mean that the finger/cursor is moving down the screen,
 *                  which means we want to scroll towards the top.
 */
Run Code Online (Sandbox Code Playgroud)