继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

ValueAnimator

米脂
关注TA
已关注
手记 492
粉丝 88
获赞 592

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();

原文链接:http://www.apkbus.com/blog-880881-63289.html

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP