public static void animateTint(ImageView view, int from, int to, int duration) {
final float[] fromHSL = new float[3];
final float[] toHSL = new float[3];
float[] currentHSL = new float[3];
ColorUtils.colorToHSL(from, fromHSL);
ColorUtils.colorToHSL(to, toHSL);
int fromAlpha = Color.alpha(from);
int toAlpha = Color.alpha(to);
final ValueAnimator anim = ObjectAnimator.ofFloat(0f, 1f);
anim.addUpdateListener((ValueAnimator animation) -> {
float mul = (Float) animation.getAnimatedValue();
ColorUtils.blendHSL(fromHSL, toHSL, mul, currentHSL);
int color = ColorUtils.HSLToColor(currentHSL);
color = ColorUtils.setAlphaComponent(color, fromAlpha +
(int) ((toAlpha - fromAlpha) * mul));
setTint(view, color);
});
anim.setDuration(duration);
anim.setInterpolator(new AccelerateDecelerateInterpolator());
anim.start();
}
ImageViewTintUtils.java 文件源码
java
阅读 15
收藏 0
点赞 0
评论 0
项目:revolution-irc
作者:
评论列表
文章目录