速度限制为滚动视图 [英] Speed limit for scroll view

查看:134
本文介绍了速度限制为滚动视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序的滚动是超级快! 如何限制滚动视图的滚动速度在我的Andr​​oid应用程序? 涡旋可以非常快,它的意义在于,速度滚动。

My app scrolling is super fast! How can I limit the scroll speed of a scroll view in my android app? The scroll can be very fast and it's meaningless to scroll in that speed.

推荐答案

这线程是老了,但我会解决部分问题回复:限制一扔速度。随意发表评论,所以我可以提高我的解决方案。

This thread is old, but I will reply with a partial solution: limiting the fling velocity. Feel free to comment so I can improve my solution.

由于在开发人员培训手册的说明:

As explained in the Developer Training guide:

急张的是,当用户拖动并迅速抬起她的手指发生滚动的类型。

Flinging is the type of scrolling that occurs when a user drags and lifts her finger quickly.

这就是我需要的速度极限。因此,在自定义滚动型(不论水平或垂直) 覆盖一扔这样的方法。

That's where I needed a velocity limit. So, in the Custom ScrollView (whether horizontal or vertical) override fling method like this.

@Override
public void fling(int velocityY) {
    int topVelocityY = (int) ((Math.min(Math.abs(velocityY), MAX_SCROLL_SPEED) ) * Math.signum(velocityY));
    super.fling(topVelocityY);
}

我发现,velocityY(水平滚动视图,这将是velocityX)可能是之间-16000和16000消极只是意味着滚动回来。我仍然在测试这个值,我也只有一台设备进行了测试。不知道这是否是在旧设备/ API版本相同。我以后还会再来编辑此。

I found that velocityY (in horizontal scrollview, it would be velocityX) could be between -16000 and 16000. Negative just means scrolling back. I'm still testing this values, and I have tested it in only one device. Not sure if it's the same in older devices/API versions. I will come back later to edit this.

(int) ((Math.min(Math.abs(velocityY), MAX_SCROLL_SPEED) ) * Math.signum(velocityY));

我在做什么有获得我不断MAX_SCROLL_SPEED和原velocityY两者中的最小值,然后获得原velocityY的迹象。我们需要标志向后滚动。

What I'm doing there is obtaining the minimum value between my constant MAX_SCROLL_SPEED and original velocityY, then obtaining the sign of the original velocityY. We need the sign to scroll back.

最后,发回修改后的velocityY。

Finally, sending back the modified velocityY.

这是一个部分的解决方案,因为如果用户保持pressing滚动视图,速度不会改变。

It's a partial solution, because if the user keeps pressing the scrollview, the speed won't change.

再次随意提高我的回答,我仍然在学习。

Again, feel free to improve my answer, I'm still learning.

这篇关于速度限制为滚动视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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