下面列出了怎么用android.animation.IntEvaluator的API类实例代码及写法,或者点击链接到github查看源代码。
@NonNull
private PropertyValuesHolder createRadiusPropertyHolder(boolean isReverse) {
String propertyName;
int startRadiusValue;
int endRadiusValue;
if (isReverse) {
propertyName = ANIMATION_RADIUS_REVERSE;
startRadiusValue = radius / 2;
endRadiusValue = radius;
} else {
propertyName = ANIMATION_RADIUS;
startRadiusValue = radius;
endRadiusValue = radius / 2;
}
PropertyValuesHolder holder = PropertyValuesHolder.ofInt(propertyName, startRadiusValue, endRadiusValue);
holder.setEvaluator(new IntEvaluator());
return holder;
}
@NonNull
private PropertyValuesHolder createStrokePropertyHolder(boolean isReverse) {
String propertyName;
int startStrokeValue;
int endStrokeValue;
if (isReverse) {
propertyName = ANIMATION_STROKE_REVERSE;
startStrokeValue = radius;
endStrokeValue = 0;
} else {
propertyName = ANIMATION_STROKE;
startStrokeValue = 0;
endStrokeValue = radius;
}
PropertyValuesHolder holder = PropertyValuesHolder.ofInt(propertyName, startStrokeValue, endStrokeValue);
holder.setEvaluator(new IntEvaluator());
return holder;
}
@NonNull
@Override
protected PropertyValuesHolder createScalePropertyHolder(boolean isReverse) {
String propertyName;
int startRadiusValue;
int endRadiusValue;
if (isReverse) {
propertyName = ANIMATION_SCALE_REVERSE;
startRadiusValue = (int) (radius * scaleFactor);
endRadiusValue = radius;
} else {
propertyName = ANIMATION_SCALE;
startRadiusValue = radius;
endRadiusValue = (int) (radius * scaleFactor);
}
PropertyValuesHolder holder = PropertyValuesHolder.ofInt(propertyName, startRadiusValue, endRadiusValue);
holder.setEvaluator(new IntEvaluator());
return holder;
}
@NonNull
protected PropertyValuesHolder createScalePropertyHolder(boolean isReverse) {
String propertyName;
int startRadiusValue;
int endRadiusValue;
if (isReverse) {
propertyName = ANIMATION_SCALE_REVERSE;
startRadiusValue = radius;
endRadiusValue = (int) (radius * scaleFactor);
} else {
propertyName = ANIMATION_SCALE;
startRadiusValue = (int) (radius * scaleFactor);
endRadiusValue = radius;
}
PropertyValuesHolder holder = PropertyValuesHolder.ofInt(propertyName, startRadiusValue, endRadiusValue);
holder.setEvaluator(new IntEvaluator());
return holder;
}
/**
* 进场动画
*/
private void in() {
int height = AndroidUtils.getScreenParams(getContext())[1];
ValueAnimator animator = ValueAnimator.ofObject(new IntEvaluator(), -height / 2, 0);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override public void onAnimationUpdate(ValueAnimator animation) {
mWpm.y = (int) animation.getAnimatedValue();
mWindow.setAttributes(mWpm);
}
});
animator.setInterpolator(new BounceInterpolator()); //弹跳
Animator alpha = ObjectAnimator.ofFloat(mRootView, "alpha", 0f, 1f);
AnimatorSet set = new AnimatorSet();
set.play(animator).with(alpha);
set.setDuration(2000).start();
}
/**
* Animates the overlay to a specified radius, fades it out, and clears the current gesture
* @param targetRadius The radius to animate the circular overlay to
* @param time The time for this animation to last
* @param alphaDelay An optional delay to add before animating the transparency of the overlay
*/
private void animateOutRadius(int targetRadius, int time, int alphaDelay) {
ObjectAnimator alphaAnim = ObjectAnimator.ofObject(
this, "overlayAlpha",
new IntEvaluator(), mAlpha, 0);
ObjectAnimator radiusAnim = ObjectAnimator.ofObject(
this, "radius",
new IntEvaluator(), (isRight() ? radius() : -radius()), targetRadius);
radiusAnim
.setDuration(time)
.setInterpolator(AnimationUtils.loadInterpolator(getContext(),
android.R.interpolator.accelerate_quad));
alphaAnim
.setDuration(time)
.setInterpolator(AnimationUtils.loadInterpolator(getContext(),
android.R.interpolator.accelerate_quad));
radiusAnim.start();
alphaAnim.setStartDelay(alphaDelay);
alphaAnim.start();
}
@Override
protected void updateView() {
intEvaluator = new IntEvaluator();
floatEvaluator = new FloatEvaluator();
int sameWidth = playOrPause.getLayoutParams().width;
screenWidth = DensityUtil.getScreenWidth(getContext());
screenHeight = DensityUtil.getScreenHeight(getContext());
int margin = ((RelativeLayout.LayoutParams) playOrPause.getLayoutParams()).rightMargin;
endPlay = screenWidth / 2 - (sameWidth * 2 + margin) + sameWidth / 2;
}
public DrawableAnimationBuilder alpha(int fromValue, int toValue) {
hashMap.put(property, new Holder(new IntEvaluator(), fromValue, toValue));
return this;
}
public T scrollX(int fromValue, int toValue) {
hashMap.put(SCROLL_X, new Holder(new IntEvaluator(), fromValue, toValue));
return (T) this;
}
public T scrollY(int fromValue, int toValue) {
hashMap.put(SCROLL_Y, new Holder(new IntEvaluator(), fromValue, toValue));
return (T) this;
}
public ImageViewAnimationBuilder imageAlpha(int fromValue, int toValue) {
hashMap.put(IMAGE_ALPHA, new Holder(new IntEvaluator(), fromValue, toValue));
return this;
}
private PropertyValuesHolder createColorPropertyHolder(String propertyName, int startValue, int endValue) {
PropertyValuesHolder holder = PropertyValuesHolder.ofInt(propertyName, startValue, endValue);
holder.setEvaluator(new IntEvaluator());
return holder;
}
private PropertyValuesHolder createSlidePropertyHolder() {
PropertyValuesHolder holder = PropertyValuesHolder.ofInt(ANIMATION_COORDINATE, coordinateStart, coordinateEnd);
holder.setEvaluator(new IntEvaluator());
return holder;
}
DimensionUpdateListener(@NonNull View view) {
this.view = view;
intEvaluator = new IntEvaluator();
}