Created
October 5, 2014 14:29
-
-
Save almozavr/f4d990fef964d0a1d4bd to your computer and use it in GitHub Desktop.
PositionResizeAnimator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PositionResizeAnimator { | |
public static Animator createAnimator(Holder srcHolder, Holder targetHolder, final View animateView) { | |
ValueAnimator heightAnimator = ValueAnimator.ofInt(srcHolder.height, targetHolder.height); | |
heightAnimator.addUpdateListener( | |
new ValueAnimator.AnimatorUpdateListener() { | |
@Override | |
public void onAnimationUpdate(ValueAnimator animation) { | |
int val = (Integer) animation.getAnimatedValue(); | |
ViewGroup.LayoutParams layoutParams = animateView.getLayoutParams(); | |
layoutParams.height = val; | |
animateView.setLayoutParams(layoutParams); | |
} | |
} | |
); | |
ValueAnimator widthAnimator = ValueAnimator.ofInt(srcHolder.width, targetHolder.width); | |
widthAnimator.addUpdateListener( | |
new ValueAnimator.AnimatorUpdateListener() { | |
@Override | |
public void onAnimationUpdate(ValueAnimator animation) { | |
int val = (Integer) animation.getAnimatedValue(); | |
ViewGroup.LayoutParams layoutParams = animateView.getLayoutParams(); | |
layoutParams.width = val; | |
animateView.setLayoutParams(layoutParams); | |
} | |
} | |
); | |
AnimatorSet set = new AnimatorSet(); | |
set.playTogether( | |
heightAnimator, | |
widthAnimator, | |
ObjectAnimator.ofFloat(animateView, View.X, srcHolder.x, targetHolder.x), | |
ObjectAnimator.ofFloat(animateView, View.Y, srcHolder.y, targetHolder.y) | |
); | |
return set; | |
} | |
public static class Holder implements Serializable { | |
public final float x; | |
public final float y; | |
public final int width; | |
public final int height; | |
public Holder(float x, float y, int width, int height) { | |
this.x = x; | |
this.y = y; | |
this.width = width; | |
this.height = height; | |
} | |
public static Holder create(View srcView) { | |
return new Holder(srcView.getX(), srcView.getY(), srcView.getMeasuredWidth(), srcView.getMeasuredHeight()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment