Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PositionResizeAnimator
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