Created
September 17, 2013 07:56
-
-
Save laaptu/6591295 to your computer and use it in GitHub Desktop.
Android Collapse Animation by decreasing height
This file contains hidden or 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
| private void animateAndDelete(final View view, final int deletePosition) { | |
| final int height = view.getMeasuredHeight(); | |
| Animation animation = new Animation() { | |
| @Override | |
| protected void applyTransformation(float interpolatedTime, | |
| Transformation t) { | |
| view.getLayoutParams().height = height | |
| - (int) (height * interpolatedTime); | |
| view.requestLayout(); | |
| } | |
| @Override | |
| public boolean willChangeBounds() { | |
| return true; | |
| } | |
| }; | |
| animation.setDuration((int) (height * view.getContext().getResources() | |
| .getDisplayMetrics().density)); | |
| animation.setInterpolator(new SmoothInterpolator()); | |
| animation.setAnimationListener(new AnimationListener() { | |
| @Override | |
| public void onAnimationStart(Animation arg0) { | |
| } | |
| @Override | |
| public void onAnimationRepeat(Animation arg0) { | |
| } | |
| @Override | |
| public void onAnimationEnd(Animation arg0) { | |
| view.setVisibility(View.GONE); | |
| } | |
| }); | |
| view.startAnimation(animation); | |
| } | |
| public class SmoothInterpolator extends LinearInterpolator { | |
| @Override | |
| public float getInterpolation(float input) { | |
| return (float) Math.pow(input - 1, 5) + 1; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment