Skip to content

Instantly share code, notes, and snippets.

@almozavr
Created October 5, 2014 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save almozavr/f4d990fef964d0a1d4bd to your computer and use it in GitHub Desktop.
Save almozavr/f4d990fef964d0a1d4bd to your computer and use it in GitHub Desktop.
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