下面列出了android.animation.PropertyValuesHolder#ofInt ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void startCircleMinor(final Callback callback) {
PropertyValuesHolder rp2 = PropertyValuesHolder.ofFloat("radius", 0, circleMaxRadius * .60f);
PropertyValuesHolder ap2 = PropertyValuesHolder.ofFloat("alpha", 1, 0);
PropertyValuesHolder sp2 = PropertyValuesHolder.ofInt("stroke", (int) (circleMaxRadius * .06f), 0);
ValueAnimator va2 = ValueAnimator.ofPropertyValuesHolder(rp2, ap2, sp2);
va2.setInterpolator(new AccelerateInterpolator(.4f));
va2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
circleRadius2 = (float) animation.getAnimatedValue("radius");
circleAlpha2 = (float) animation.getAnimatedValue("alpha");
circleStroke2 = (int) animation.getAnimatedValue("stroke");
callback.onValueUpdated();
}
});
va2.setDuration(380);
va2.start();
}
PropertyValuesHolder createColorPropertyHolder(boolean isReverse) {
String propertyName;
int colorStart;
int colorEnd;
if (isReverse) {
propertyName = ANIMATION_COLOR_REVERSE;
colorStart = this.colorEnd;
colorEnd = this.colorStart;
} else {
propertyName = ANIMATION_COLOR;
colorStart = this.colorStart;
colorEnd = this.colorEnd;
}
PropertyValuesHolder holder = PropertyValuesHolder.ofInt(propertyName, colorStart, colorEnd);
holder.setEvaluator(new ArgbEvaluator());
return holder;
}
@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;
}
public void testPropertyValuesHolder(View v) {
if (mTestSwitch) {
PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("x", 50f);
PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("y", 600f);
// 同时进行X轴和Y轴的动画
ObjectAnimator xyAnimator = ObjectAnimator.ofPropertyValuesHolder(mTestPropertyValuesHolderBtn, pvhX, pvhY);
xyAnimator.setDuration(C.Int.ANIM_DURATION * 2);
xyAnimator.start();
} else {
int left = v.getLeft();
int right = v.getRight();
// 将view左边增加10像素
PropertyValuesHolder pvhLeft = PropertyValuesHolder.ofInt("left", left, left + 10);
// 将view右边减少10像素
PropertyValuesHolder pvhRight = PropertyValuesHolder.ofInt("right", right, right - 10);
// 在X轴缩放从原始比例1f,缩小到最小0f,再放大到原始比例1f
PropertyValuesHolder pvhScaleX = PropertyValuesHolder.ofFloat("scaleX", 1f, 0f, 1f);
// 在Y轴缩放从原始比例1f,缩小到最小0f,再放大到原始比例1f
PropertyValuesHolder pvhScaleY = PropertyValuesHolder.ofFloat("scaleY", 1f, 0f, 1f);
// 将PropertyValuesHolder交付给ObjectAnimator进行构建
ObjectAnimator customAnim = ObjectAnimator.ofPropertyValuesHolder(v, pvhLeft, pvhRight, pvhScaleX, pvhScaleY);
customAnim.setDuration(C.Int.ANIM_DURATION * 2);
customAnim.start();
}
mTestSwitch = !mTestSwitch;
}
private LayoutTransition createTransitionChange() {
LayoutTransition mTransitioner = new LayoutTransition();
//入场动画:view在这个容器中消失时触发的动画
ObjectAnimator animIn = ObjectAnimator.ofFloat(null, "rotationY", 0f, 360f, 0f);
mTransitioner.setAnimator(LayoutTransition.APPEARING, animIn);
//出场动画:view显示时的动画
ObjectAnimator animOut = ObjectAnimator.ofFloat(null, "rotation", 0f, 90f, 0f);
mTransitioner.setAnimator(LayoutTransition.DISAPPEARING, animOut);
PropertyValuesHolder pvhLeft = PropertyValuesHolder.ofInt("left", 0, 100, 0);
PropertyValuesHolder pvhTop = PropertyValuesHolder.ofInt("top", 0, 0);
PropertyValuesHolder pvhRight = PropertyValuesHolder.ofInt("right", 0, 0);
PropertyValuesHolder pvhBottom = PropertyValuesHolder.ofInt("bottom", 0, 0);
Animator changeAppearAnimator = ObjectAnimator.ofPropertyValuesHolder(layoutTransitionGroup,
pvhLeft, pvhTop, pvhRight, pvhBottom);
mTransitioner.setAnimator(LayoutTransition.CHANGE_APPEARING, changeAppearAnimator);
/*
1, LayoutTransition.CHANGE_APPEARING/CHANGE_DISAPPEARING 必须配合PropertyValuesHolder使用才能有效果(使用ObjectAnimator无效).
*/
return mTransitioner;
}
/**
* This method creates an animator that changes ImageView position on the screen.
* It will look like view is translated from its position on previous screen to its new position on this screen
*/
@NonNull
private ObjectAnimator createEnteringImagePositionAnimator() {
PropertyValuesHolder propertyLeft = PropertyValuesHolder.ofInt("left", mAnimatedImage.getLeft(), mToLeft);
PropertyValuesHolder propertyTop = PropertyValuesHolder.ofInt("top", mAnimatedImage.getTop(), mToTop - getStatusBarHeight());
PropertyValuesHolder propertyRight = PropertyValuesHolder.ofInt("right", mAnimatedImage.getRight(), mToLeft + mToWidth);
PropertyValuesHolder propertyBottom = PropertyValuesHolder.ofInt("bottom", mAnimatedImage.getBottom(), mToTop + mToHeight - getStatusBarHeight());
ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(mAnimatedImage, propertyLeft, propertyTop, propertyRight, propertyBottom);
animator.addListener(new SimpleAnimationListener() {
@Override
public void onAnimationEnd(Animator animation) {
// set new parameters of animated ImageView. This will prevent blinking of view when set visibility to visible in Exit animation
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) mAnimatedImage.getLayoutParams();
layoutParams.height = mImageTo.getHeight();
layoutParams.width = mImageTo.getWidth();
layoutParams.setMargins(mToLeft, mToTop - getStatusBarHeight(), 0, 0);
}
});
return animator;
}
/**
* This method creates an animator that changes ImageView position on the screen.
* It will look like view is translated from its position on this screen to its position on previous screen
*/
@NonNull
private ObjectAnimator createExitingImagePositionAnimator() {
// get initial location on the screen and start animation from there
int[] locationOnScreen = new int[2];
mAnimatedImage.getLocationOnScreen(locationOnScreen);
PropertyValuesHolder propertyLeft = PropertyValuesHolder.ofInt("left",
locationOnScreen[0],
mToLeft);
PropertyValuesHolder propertyTop = PropertyValuesHolder.ofInt("top",
locationOnScreen[1] - getStatusBarHeight(),
mToTop - getStatusBarHeight());
PropertyValuesHolder propertyRight = PropertyValuesHolder.ofInt("right",
locationOnScreen[0] + mAnimatedImage.getWidth(),
mToLeft + mToWidth);
PropertyValuesHolder propertyBottom = PropertyValuesHolder.ofInt("bottom",
mAnimatedImage.getBottom(),
mToTop + mToHeight - getStatusBarHeight());
return ObjectAnimator.ofPropertyValuesHolder(mAnimatedImage, propertyLeft, propertyTop, propertyRight, propertyBottom);
}
public void startLeftGunDong() {
if (animatorL != null && animatorL.isRunning()) {
return;
}
PropertyValuesHolder xholder = PropertyValuesHolder.ofInt("scrollX", 0, -220);
animatorL = ObjectAnimator.ofPropertyValuesHolder(left_iv, xholder);
setAnimatorProperty(animatorL);
animatorL.start();
}
public void startCenterGunDong() {
if (animatorCL != null && animatorCL.isRunning()) {
return;
}
PropertyValuesHolder xLeftholder = PropertyValuesHolder.ofInt("scrollX", 0, 220);
PropertyValuesHolder xRightholder = PropertyValuesHolder.ofInt("scrollX", 0, -220);
animatorCL = ObjectAnimator.ofPropertyValuesHolder(center_iv_left, xLeftholder);
animatorCR = ObjectAnimator.ofPropertyValuesHolder(center_iv_right, xRightholder);
setAnimatorProperty(animatorCL);
setAnimatorProperty(animatorCR);
animatorCL.start();
animatorCR.start();
}
@NonNull
public static <T> ObjectAnimator ofInt(@Nullable T target,
@NonNull Property<T, Integer> xProperty,
@NonNull Property<T, Integer> yProperty,
@NonNull Path path) {
int[] xValues = new int[NUM_POINTS];
int[] yValues = new int[NUM_POINTS];
calculateXYValues(path, xValues, yValues);
PropertyValuesHolder xPvh = PropertyValuesHolder.ofInt(xProperty, xValues);
PropertyValuesHolder yPvh = PropertyValuesHolder.ofInt(yProperty, yValues);
return ObjectAnimator.ofPropertyValuesHolder(target, xPvh, yPvh);
}
protected void changeZDepth(ZDepth zDepth) {
int newAlphaTopShadow = zDepth.getAlphaTopShadow();
int newAlphaBottomShadow = zDepth.getAlphaBottomShadow();
float newOffsetYTopShadow = zDepth.getOffsetYTopShadowPx(getContext());
float newOffsetYBottomShadow = zDepth.getOffsetYBottomShadowPx(getContext());
float newBlurTopShadow = zDepth.getBlurTopShadowPx(getContext());
float newBlurBottomShadow = zDepth.getBlurBottomShadowPx(getContext());
if (!mZDepthDoAnimation) {
mZDepthParam.mAlphaTopShadow = newAlphaTopShadow;
mZDepthParam.mAlphaBottomShadow = newAlphaBottomShadow;
mZDepthParam.mOffsetYTopShadowPx = newOffsetYTopShadow;
mZDepthParam.mOffsetYBottomShadowPx = newOffsetYBottomShadow;
mZDepthParam.mBlurTopShadowPx = newBlurTopShadow;
mZDepthParam.mBlurBottomShadowPx = newBlurBottomShadow;
mShadow.setParameter(mZDepthParam,
mZDepthPaddingLeft,
mZDepthPaddingTop,
getWidth() - mZDepthPaddingRight,
getHeight() - mZDepthPaddingBottom);
invalidate();
return;
}
int nowAlphaTopShadow = mZDepthParam.mAlphaTopShadow;
int nowAlphaBottomShadow = mZDepthParam.mAlphaBottomShadow;
float nowOffsetYTopShadow = mZDepthParam.mOffsetYTopShadowPx;
float nowOffsetYBottomShadow = mZDepthParam.mOffsetYBottomShadowPx;
float nowBlurTopShadow = mZDepthParam.mBlurTopShadowPx;
float nowBlurBottomShadow = mZDepthParam.mBlurBottomShadowPx;
PropertyValuesHolder alphaTopShadowHolder = PropertyValuesHolder.ofInt(ANIM_PROPERTY_ALPHA_TOP_SHADOW,
nowAlphaTopShadow,
newAlphaTopShadow);
PropertyValuesHolder alphaBottomShadowHolder = PropertyValuesHolder.ofInt(ANIM_PROPERTY_ALPHA_BOTTOM_SHADOW,
nowAlphaBottomShadow,
newAlphaBottomShadow);
PropertyValuesHolder offsetTopShadowHolder = PropertyValuesHolder.ofFloat(ANIM_PROPERTY_OFFSET_TOP_SHADOW,
nowOffsetYTopShadow,
newOffsetYTopShadow);
PropertyValuesHolder offsetBottomShadowHolder = PropertyValuesHolder.ofFloat(ANIM_PROPERTY_OFFSET_BOTTOM_SHADOW,
nowOffsetYBottomShadow,
newOffsetYBottomShadow);
PropertyValuesHolder blurTopShadowHolder = PropertyValuesHolder.ofFloat(ANIM_PROPERTY_BLUR_TOP_SHADOW,
nowBlurTopShadow,
newBlurTopShadow);
PropertyValuesHolder blurBottomShadowHolder = PropertyValuesHolder.ofFloat(ANIM_PROPERTY_BLUR_BOTTOM_SHADOW,
nowBlurBottomShadow,
newBlurBottomShadow);
ValueAnimator anim = ValueAnimator
.ofPropertyValuesHolder(
alphaTopShadowHolder,
alphaBottomShadowHolder,
offsetTopShadowHolder,
offsetBottomShadowHolder,
blurTopShadowHolder,
blurBottomShadowHolder);
anim.setDuration(mZDepthAnimDuration);
anim.setInterpolator(new LinearInterpolator());
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int alphaTopShadow = (Integer) animation.getAnimatedValue(ANIM_PROPERTY_ALPHA_TOP_SHADOW);
int alphaBottomShadow = (Integer) animation.getAnimatedValue(ANIM_PROPERTY_ALPHA_BOTTOM_SHADOW);
float offsetTopShadow = (Float) animation.getAnimatedValue(ANIM_PROPERTY_OFFSET_TOP_SHADOW);
float offsetBottomShadow = (Float) animation.getAnimatedValue(ANIM_PROPERTY_OFFSET_BOTTOM_SHADOW);
float blurTopShadow = (Float) animation.getAnimatedValue(ANIM_PROPERTY_BLUR_TOP_SHADOW);
float blurBottomShadow = (Float) animation.getAnimatedValue(ANIM_PROPERTY_BLUR_BOTTOM_SHADOW);
mZDepthParam.mAlphaTopShadow = alphaTopShadow;
mZDepthParam.mAlphaBottomShadow = alphaBottomShadow;
mZDepthParam.mOffsetYTopShadowPx = offsetTopShadow;
mZDepthParam.mOffsetYBottomShadowPx = offsetBottomShadow;
mZDepthParam.mBlurTopShadowPx = blurTopShadow;
mZDepthParam.mBlurBottomShadowPx = blurBottomShadow;
mShadow.setParameter(mZDepthParam,
mZDepthPaddingLeft,
mZDepthPaddingTop,
getWidth() - mZDepthPaddingRight,
getHeight() - mZDepthPaddingBottom);
invalidate();
}
});
anim.start();
}
private PropertyValuesHolder createPropertyValuesHolder(String prop, float startValue, float endValue) {
return PropertyValuesHolder.ofInt(prop, (int) startValue, (int) endValue);
}
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;
}
private Animator prepareBoundsAnimator(View child, ChildBounds bounds) {
int startLeft = bounds.start.left;
int startTop = bounds.start.top;
int startRight = bounds.start.right;
int startBottom = bounds.start.bottom;
int endLeft = bounds.end.left;
int endTop = bounds.end.top;
int endRight = bounds.end.right;
int endBottom = bounds.end.bottom;
int changeCount = 0;
if (startLeft != endLeft) {
child.setLeft(startLeft);
changeCount++;
}
if (startTop != endTop) {
child.setTop(startTop);
changeCount++;
}
if (startRight != endRight) {
child.setRight(startRight);
changeCount++;
}
if (startBottom != endBottom) {
child.setBottom(startBottom);
changeCount++;
}
if (changeCount == 0) {
return null;
}
PropertyValuesHolder pvh[] = new PropertyValuesHolder[changeCount];
int pvhIndex = -1;
if (startLeft != endLeft) {
pvh[++pvhIndex] = PropertyValuesHolder.ofInt("left", startLeft, endLeft);
}
if (startTop != endTop) {
pvh[++pvhIndex] = PropertyValuesHolder.ofInt("top", startTop, endTop);
}
if (startRight != endRight) {
pvh[++pvhIndex] = PropertyValuesHolder.ofInt("right", startRight, endRight);
}
if (startBottom != endBottom) {
pvh[++pvhIndex] = PropertyValuesHolder.ofInt("bottom", startBottom, endBottom);
}
return ObjectAnimator.ofPropertyValuesHolder(child, pvh);
}
private Animator prepareBoundsAnimator(View child, ChildBounds bounds) {
int startLeft = bounds.start.left;
int startTop = bounds.start.top;
int startRight = bounds.start.right;
int startBottom = bounds.start.bottom;
int endLeft = bounds.end.left;
int endTop = bounds.end.top;
int endRight = bounds.end.right;
int endBottom = bounds.end.bottom;
int changeCount = 0;
if (startLeft != endLeft) {
child.setLeft(startLeft);
changeCount++;
}
if (startTop != endTop) {
child.setTop(startTop);
changeCount++;
}
if (startRight != endRight) {
child.setRight(startRight);
changeCount++;
}
if (startBottom != endBottom) {
child.setBottom(startBottom);
changeCount++;
}
if (changeCount == 0) {
return null;
}
PropertyValuesHolder pvh[] = new PropertyValuesHolder[changeCount];
int pvhIndex = -1;
if (startLeft != endLeft) {
pvh[++pvhIndex] = PropertyValuesHolder.ofInt("left", startLeft, endLeft);
}
if (startTop != endTop) {
pvh[++pvhIndex] = PropertyValuesHolder.ofInt("top", startTop, endTop);
}
if (startRight != endRight) {
pvh[++pvhIndex] = PropertyValuesHolder.ofInt("right", startRight, endRight);
}
if (startBottom != endBottom) {
pvh[++pvhIndex] = PropertyValuesHolder.ofInt("bottom", startBottom, endBottom);
}
return ObjectAnimator.ofPropertyValuesHolder(child, pvh);
}
@Override
protected List<ValueAnimator> setupAnimation() {
radiusValueHolder = PropertyValuesHolder.ofInt("radius", radius, 5);
opacityValueHolder = PropertyValuesHolder.ofInt("opacity", 250, 20);
for(int i = 0; i < valueAnimators.length; i++){
setAnimator(i);
}
return Arrays.asList(valueAnimators);
}