android scrollto能否实现动画效果

avatar
作者
筋斗云
阅读量:0

是的,Android中的scrollTo方法可以实现滚动的动画效果。可以通过使用属性动画(ObjectAnimator)或者ValueAnimator来实现滚动的动画效果,具体可以参考以下代码示例:

使用属性动画(ObjectAnimator)实现滚动动画效果:

ObjectAnimator.ofInt(scrollView, "scrollY", scrollY).setDuration(500).start(); 

使用值动画(ValueAnimator)实现滚动动画效果:

ValueAnimator animator = ValueAnimator.ofInt(scrollView.getScrollY(), scrollY); animator.setDuration(500); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {     @Override     public void onAnimationUpdate(ValueAnimator animation) {         int value = (int) animation.getAnimatedValue();         scrollView.scrollTo(0, value);     } }); animator.start(); 

以上代码示例中,scrollView表示要实现滚动动画的View,scrollY表示要滚动到的位置。通过属性动画或者值动画来改变View的scrollY属性实现滚动效果,从而实现滚动的动画效果。

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!