颜色渐变工具类
通过一个百分比来设置颜色从一个色调变成另一个色调的渐变过程;
ColorUtil.evaluateColor(float fraction, Object startValue, Object endValue)
方法中的三个参数:
@param fraction : 百分比
@param startValue: 设置颜色的开始颜色
@param endValue: 设置颜色的结束颜色
工具类代码如下:
public class ColorUtil {
public static Object evaluateColor(float fraction, Object startValue,
Object endValue) {
int startInt = (Integer) startValue;
int startA = (startInt >> 24) & 0xff;
int startR = (startInt >> 16) & 0xff;
int startG = (startInt >> 8) & 0xff;
int startB = startInt & 0xff;
int endInt = (Integer) endValue;
int endA = (endInt >> 24) & 0xff;
int endR = (endInt >> 16) & 0xff;
int endG = (endInt >> 8) & 0xff;
int endB = endInt & 0xff;
return (int) ((startA + (int) (fraction * (endA - startA))) << 24)
| (int) ((startR + (int) (fraction * (endR - startR))) << 16)
| (int) ((startG + (int) (fraction * (endG - startG))) << 8)
| (int) ((startB + (int) (fraction * (endB - startB))));
}
}