在安卓里面,动画的背景色渐变(比如又红色变为蓝色)是依靠属性动画来完成的,属性动画大部分情况下是来实现View的运动动画的,因为View的背景也是View的属性之一,所以属性动画自然也就可以让view的背景产生渐变的效果,代码如下:
View v = ...;//实例化一个View
private static final int RED = 0xffFF8080;
private static final int BLUE = 0xff8080FF;
private static final int CYAN = 0xff80ffff;
private static final int GREEN = 0xff80ff80;
ValueAnimator colorAnim = ObjectAnimator.ofInt(view,"backgroundColor", RED, BLUE);
colorAnim.setDuration(3000);
colorAnim.setEvaluator(new ArgbEvaluator()); colorAnim.setRepeatCount(ValueAnimator.INFINITE);
colorAnim.setRepeatMode(ValueAnimator.REVERSE);
colorAnim.start();

本文介绍如何使用安卓属性动画实现视图背景颜色渐变效果,通过ObjectAnimator.ofInt方法结合ArgbEvaluator,使View背景从一种颜色平滑过渡到另一种颜色。

2668

被折叠的 条评论
为什么被折叠?



