ValueAnimator intAnimator = ValueAnimator.ofInt(200, -100);
intAnimator.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
Integer animatedValue = (Integer) animation.getAnimatedValue();
view.scrollTo(animatedValue, 0);
}
});
intAnimator.setDuration(DURATION);
intAnimator.start();
下面是浮点型:
ValueAnimator floatAnimator = ValueAnimator.ofFloat(-100.0f, 50.5f);
floatAnimator.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
Float animatedValue = (Float) animation.getAnimatedValue();
view.scrollTo(0, animatedValue.intValue());
}
});
floatAnimator.setDuration(DURATION);
floatAnimator.start();
传入一个对象:
ValueAnimator argbAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), 0xffffff00, 0x880033ff);
argbAnimator.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
Integer animatedValue = (Integer) animation.getAnimatedValue();
textView.setBackgroundColor(animatedValue);
}
});
argbAnimator.setDuration(DURATION);
argbAnimator.start();
从一个XML文件获取值
ValueAnimator animator = (ValueAnimator) AnimatorInflater.loadAnimator(ValueAnimatorActivity.this, R.animator.valueanimator);
animator.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
Integer animatedValue = (Integer) animation.getAnimatedValue();
view.scrollTo(animatedValue, 0);
}
});
animator.start();
共同学习,写下你的评论
评论加载中...
作者其他优质文章