缓慢向上滚动 ScrollView
问题是“如何非常平滑且缓慢地将 ScrollView 滚动到顶部”。
在我的特殊情况下,我需要在大约 1-2 秒内滚动到顶部。 我尝试使用处理程序手动插值(调用scrollTo(0, y)),但这根本不起作用。
我已经在一些图书阅读器应用程序上看到了这种效果,所以一定有办法,我确定:D。 (文本非常缓慢地向上滚动以继续阅读而无需触摸屏幕进行输入)。
The question is "How do i scroll up a ScrollView to top very smoothly and slowly".
In my special case i need to scroll to top in about 1-2 seconds.
Ive tried interpolating manually using a Handler (calling scrollTo(0, y)) but that didnt work at all.
I've seen this effect on some bookreader-apps yet, so there must be a way, im sure :D.
(Text is very slowly scrolling up to go on reading without touching the screen, doing input).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我使用对象动画器(API >= 3 中可用)完成了它,它看起来非常好:
定义一个对象动画器:
final ObjectAnimator animScrollToTop = ObjectAnimator.ofInt(this, "scrollY", 0);
(
this
指的是扩展 Android 的ScrollView
的类)你可以根据需要设置其持续时间:
animScrollToTop.setDuration(2000);
(2 秒)Ps 不要忘记启动动画。
I did it using object animator (Available in API >= 3) and it looks very good:
Define an ObjectAnimator:
final ObjectAnimator animScrollToTop = ObjectAnimator.ofInt(this, "scrollY", 0);
(
this
refers to the class extending Android'sScrollView
)you can set its duration as you wish:
animScrollToTop.setDuration(2000);
(2 seconds)P.s. Don't forget to start the animation.
2秒内将滚动视图移动到2000的位置
In 2 seconds move the scroll view to the possition of 2000
尝试以下代码:
Try the following code:
您尝试过
smoothScrollTo(int x, int y)
吗?您无法设置速度参数,但也许这个功能适合您
Have you tried
smoothScrollTo(int x, int y)
?You can't set the speed parameter but maybe this function will be ok for you
您可以使用 Timer 和 TimerTask 类。你可以做类似的事情
You could use the Timer and TimerTask class. You could do something like