本文整理汇总了Java中android.animation.ArgbEvaluator.evaluate方法的典型用法代码示例。如果您正苦于以下问题:Java ArgbEvaluator.evaluate方法的具体用法?Java ArgbEvaluator.evaluate怎么用?Java ArgbEvaluator.evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.animation.ArgbEvaluator
的用法示例。
在下文中一共展示了ArgbEvaluator.evaluate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startAnim
import android.animation.ArgbEvaluator; //导入方法依赖的package包/类
/**
* 给背景设置一个动画
*
* @param endProgress 动画的结束进度
* @param endCallback 动画结束时触发
*/
private void startAnim(float endProgress, final Runnable endCallback) {
// 获取一个最终的颜色
int finalColor = Resource.Color.WHITE; // UiCompat.getColor(getResources(), R.color.white);
// 运算当前进度的颜色
ArgbEvaluator evaluator = new ArgbEvaluator();
int endColor = (int) evaluator.evaluate(endProgress, mBgDrawable.getColor(), finalColor);
// 构建一个属性动画
ValueAnimator valueAnimator = ObjectAnimator.ofObject(this, property, evaluator, endColor);
valueAnimator.setDuration(1500); // 时间
valueAnimator.setIntValues(mBgDrawable.getColor(), endColor); // 开始结束值
valueAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
// 结束时触发
endCallback.run();
}
});
valueAnimator.start();
}
示例2: onPageScrolled
import android.animation.ArgbEvaluator; //导入方法依赖的package包/类
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
this.position = position;
ArgbEvaluator evaluator = new ArgbEvaluator(); // ARGB求值器
int evaluate = colors[0]; // 初始默认颜色(透明白)
int startColor = colors[this.position <= 0 ? 0 : position];
int endColor;
if (position == 0){
endColor = colors[position +1];
}else {
endColor = colors[position +1 >=colors.length ? colors.length -1 : position +1];
}
evaluate = (Integer) evaluator.evaluate(positionOffset, startColor, endColor); // 根据positionOffset和第0页~第1页的颜色转换范围取颜色值
mViewRoot.setBackgroundColor(evaluate);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(evaluate);
}
}
示例3: updateColor
import android.animation.ArgbEvaluator; //导入方法依赖的package包/类
private void updateColor(@NonNull ArgbEvaluator colorEvaluator) {
float fraction;
int colorFrom;
int colorTo;
if (colorIntermediate != -1) {
colorFrom = alpha <= 0f ? colorMore : colorIntermediate;
colorTo = alpha <= 0f ? colorIntermediate : colorLess;
fraction = alpha <= 0 ? (1 + alpha / 45f) : alpha / 45f;
} else {
colorFrom = colorMore;
colorTo = colorLess;
fraction = (alpha + 45f) / 90f;
}
color = (int) colorEvaluator.evaluate(fraction, colorFrom, colorTo);
paint.setColor(color);
}
示例4: updateColor
import android.animation.ArgbEvaluator; //导入方法依赖的package包/类
private void updateColor(ArgbEvaluator colorEvaluator) {
float fraction;
int colorFrom;
int colorTo;
if (colorIntermediate != -1) {
colorFrom = alpha <= 0f ? colorMore : colorIntermediate;
colorTo = alpha <= 0f ? colorIntermediate : colorLess;
fraction = alpha <= 0 ? (1 + alpha / 45f) : alpha / 45f;
} else {
colorFrom = colorMore;
colorTo = colorLess;
fraction = (alpha + 45f) / 90f;
}
color = (int) colorEvaluator.evaluate(fraction, colorFrom, colorTo);
paint.setColor(color);
}
示例5: updateViewWithPercent
import android.animation.ArgbEvaluator; //导入方法依赖的package包/类
@Override
void updateViewWithPercent(View child, float percent) {
super.updateViewWithPercent(child, percent);
float newX = targetX == UNSPECIFIED_INT ? 0 : (targetX - mStartX) * percent;
float newY = targetY == UNSPECIFIED_INT ? 0 : (targetY - mStartY) * percent;
// set scale
if (targetWidth != UNSPECIFIED_INT || targetHeight != UNSPECIFIED_INT) {
float newWidth = mStartWidth + ((targetWidth - mStartWidth) * percent);
float newHeight = mStartHeight + ((targetHeight - mStartHeight) * percent);
child.setScaleX(newWidth / mStartWidth);
child.setScaleY(newHeight / mStartHeight);
// make up position for scale change
newX -= (mStartWidth - newWidth) / 2;
newY -= (mStartHeight - newHeight) / 2;
}
// set new position
child.setTranslationX(newX);
child.setTranslationY(newY);
// set alpha
if (targetAlpha != UNSPECIFIED_FLOAT) {
child.setAlpha(mStartAlpha + (targetAlpha - mStartAlpha) * percent);
}
// set background color
if (targetBackgroundColor != UNSPECIFIED_INT && mStartBackgroundColor != 0) {
ArgbEvaluator evaluator = new ArgbEvaluator();
int color = (int) evaluator.evaluate(percent, mStartBackgroundColor, targetBackgroundColor);
child.setBackgroundColor(color);
}
// set rotation
if (targetRotateX != UNSPECIFIED_FLOAT) {
child.setRotationX(mStartRotateX + (targetRotateX - mStartRotateX) * percent);
}
if (targetRotateY != UNSPECIFIED_FLOAT) {
child.setRotationY(mStartRotateY + (targetRotateY - mStartRotateY) * percent);
}
child.requestLayout();
}