我有滚动视图。我执行smooth-scroll.using smoothScrollBy()。它一切正常,但我想更改平滑滚动的持续时间。平滑滚动发生得非常快,用户不知道发生了什么。请帮助我降低平滑滚动速度?降低滚动视图中的平滑滚动的速度
21
A
回答
1
下面是与使用scrollTo计时器的解决方案,但你也可以使用scrollBy Android: HorizontalScrollView smoothScroll animation time
-1
whichScreen = Math.max(0, Math.min(whichScreen, getBase().getDocumentModel().getPageCount()-1));
mNextScreen = whichScreen;
final int newX = whichScreen * getWidth();
final int delta = newX - getScrollX();
//scroller.startScroll(getScrollX(), 0, delta, 0, Math.abs(delta) * 2);
scroller.startScroll(getScrollX(), 0, delta, 0, Math.abs(delta));
invalidate();
10
试试下面的代码:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
{
ValueAnimator realSmoothScrollAnimation =
ValueAnimator.ofInt(parentScrollView.getScrollY(), targetScrollY);
realSmoothScrollAnimation.setDuration(500);
realSmoothScrollAnimation.addUpdateListener(new AnimatorUpdateListener()
{
@Override
public void onAnimationUpdate(ValueAnimator animation)
{
int scrollTo = (Integer) animation.getAnimatedValue();
parentScrollView.scrollTo(0, scrollTo);
}
});
realSmoothScrollAnimation.start();
}
else
{
parentScrollView.smoothScrollTo(0, targetScrollY);
}
2
这是我如何实现平稳垂直滚动(如电影信用)。这也允许用户上下移动滚动并允许它们在放开时继续滚动。在我的XML中,我将我的TextView封装在名为“scrollView1”的ScrollView中。请享用!
final TextView tv=(TextView)findViewById(R.id.lyrics);
final ScrollView scrollView = (ScrollView) findViewById(R.id.scrollView1);
Button start = (Button) findViewById(R.id.button_start);
Button stop = (Button) findViewById(R.id.button_stop);
final Handler timerHandler = new Handler();
final Runnable timerRunnable = new Runnable() {
@Override
public void run() {
scrollView.smoothScrollBy(0,5); // 5 is how many pixels you want it to scroll vertically by
timerHandler.postDelayed(this, 10); // 10 is how many milliseconds you want this thread to run
}
};
start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
timerHandler.postDelayed(timerRunnable, 0);
}
});
stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
timerHandler.removeCallbacks(timerRunnable);
}
});
+0
我将如何知道滚动到底并且runnable必须关闭?如何处理这个? – AlexKost
111
相关问题
- 1. 如何降低UIScrollview的滚动速度?
- 2. 滚动视图的平滑滚动
- 3. 如何降低UIScroll视图的滚动速度
- 4. 如何降低Flex移动SpinnerList组件的滚动速度
- 5. 快速平滑滚动鼠标滚轮
- 6. 如何在水平滚动视图中使用平滑滚动居中视图
- 7. 表视图的平滑滚动
- 8. 在列表视图中平滑滚动
- 9. javascript滚动到视图与平滑滚动效果的div?
- 10. 滚动速度自动滚动速度
- 11. 水平滚动视图迅速的Xcode
- 12. 视差滚动平滑
- 13. 平滑滚动,其中每个内容以不同的速度滚动
- 14. 平滑滚动
- 15. 平滑滚动 -
- 16. 平滑滚动
- 17. 停止滚动视图动画时低于某个速度
- 18. 的tableview平滑滚动迅速
- 19. android水平recyclerview在垂直嵌套滚动视图中的平滑滚动
- 20. JavaScript的“平滑滚动”不会滚动
- 21. 滚动后降低标题高度
- 22. 列表视图不平滑滚动
- 23. 滚动视图不是平滑滚动使用lazyloader
- 24. Android中的可滚动滑动视图
- 25. 使用滚动视图内的两个列表视图进行平滑滚动
- 26. 如何播放滚动视图滚动时依靠滚动视图滚动速度的声音?
- 27. 滚动查看滚动视图时的水平滚动
- 28. 水平滚动页面中的水平滚动视图
- 29. 水平滚动图像组在启动后滚动滚动,然后平滑
- 30. Android中的滑动菜单和水平滚动视图
这应该被选为答案这个问题。 +1 –
而不是使用ValueAnimator,为什么不使用ObjectAnimator(ValueAnimator的子类)?它使得它更容易 - 实际上是一个单线程,ObjectAnimator.ofInt(scrollView,“scrollY”,targetScrollY).setDuration(500).start(); –