List of usage examples for android.view.animation Animation Animation
public Animation()
From source file:Main.java
public static void expand(final View v) { v.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); final int targtetHeight = v.getMeasuredHeight(); v.getLayoutParams().height = 0;/*from w w w. jav a 2s. co m*/ v.setVisibility(View.VISIBLE); Animation a = new Animation() { @Override protected void applyTransformation(float interpolatedTime, Transformation t) { v.getLayoutParams().height = interpolatedTime == 1 ? LayoutParams.WRAP_CONTENT : (int) (targtetHeight * interpolatedTime); v.requestLayout(); } @Override public boolean willChangeBounds() { return true; } }; a.setDuration(300); v.startAnimation(a); }
From source file:Main.java
public static void animateHeight(final View animated, final int from, final int to, final long duration, final Interpolator interpolator, final AnimationListener animationListener) { final Animation animation = new Animation() { @Override/*from w w w .jav a 2s . co m*/ protected void applyTransformation(float interpolatedTime, Transformation t) { final int newHeight = (int) (from + (to - from) * interpolatedTime); setHeight(animated, newHeight); } @Override public boolean willChangeBounds() { return true; } }; animation.setDuration(duration); animation.setInterpolator(interpolator); if (animationListener != null) { animation.setAnimationListener(animationListener); } animated.startAnimation(animation); }
From source file:Main.java
public static void expand(final View drawer) { drawer.measure(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); final int targetHeight = drawer.getMeasuredHeight(); //make the height of the draw 0px drawer.getLayoutParams().height = 0; //make it visible (no blink will occur since view has no height) drawer.setVisibility(View.VISIBLE); Animation anim = new Animation() { @Override/*from w w w . j ava2 s . c o m*/ protected void applyTransformation(float interpolatedTime, Transformation t) { //1 means animation has completed drawer.getLayoutParams().height = interpolatedTime == 1 ? LinearLayout.LayoutParams.WRAP_CONTENT //else height is a fraction of time remaining : (int) (targetHeight * interpolatedTime); //force layout invalidation drawer.requestLayout(); } @Override public boolean willChangeBounds() { //return true since it will change bounds of view being animated return true; } }; anim.setDuration(ANIMATION_DURATION_SHORT); drawer.startAnimation(anim); }
From source file:Main.java
public static void collapse(final View view, final AnimationListener animationListener) { if (view == null) { return;//from www . ja v a 2 s . co m } final int initialHeight = view.getMeasuredHeight(); final Animation animation = new Animation() { @Override protected void applyTransformation(final float interpolatedTime, final Transformation t) { if (interpolatedTime == 1) { view.setVisibility(View.GONE); } else { setHeight(view, initialHeight - (int) (initialHeight * interpolatedTime)); view.requestLayout(); } } @Override public boolean willChangeBounds() { return true; } }; animation.setDuration(ANIMATION_DURATION); // return animation; if (animationListener != null) { animation.setAnimationListener(animationListener); } view.startAnimation(animation); }
From source file:Main.java
public static void expand(final View v, Activity activity) { v.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); Resources r = activity.getResources(); final float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 200, r.getDisplayMetrics()); final int targtetHeight = (int) px;//200;//v.getMeasuredHeight(); v.getLayoutParams().height = 0;/*from w w w.j a va2 s . c o m*/ v.setVisibility(View.VISIBLE); Animation a = new Animation() { @Override protected void applyTransformation(float interpolatedTime, Transformation t) { v.getLayoutParams().height = interpolatedTime == 1 ? ((int) px)//200//ViewGroup.LayoutParams.WRAP_CONTENT : (int) (targtetHeight * interpolatedTime); v.requestLayout(); } @Override public boolean willChangeBounds() { return true; } }; a.setDuration((int) (targtetHeight / v.getContext().getResources().getDisplayMetrics().density)); v.startAnimation(a); }
From source file:Main.java
public static void expand(final View v, boolean isHalf) { v.measure(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); targetHeight = v.getMeasuredHeight(); if (isHalf) { targetHeight = targetHeight / 2; }//from w w w.j a va 2 s.co m // Older versions of android (pre API 21) cancel animations for views with a height of 0. v.getLayoutParams().height = 1; v.setVisibility(View.VISIBLE); Animation a = new Animation() { @Override protected void applyTransformation(float interpolatedTime, Transformation t) { v.getLayoutParams().height = interpolatedTime == 1 ? RelativeLayout.LayoutParams.WRAP_CONTENT : (int) (targetHeight * interpolatedTime); v.requestLayout(); } @Override public boolean willChangeBounds() { return true; } }; // 1dp/ms a.setDuration((int) (targetHeight / v.getContext().getResources().getDisplayMetrics().density)); v.startAnimation(a); }
From source file:Main.java
public static Animation getCollapseViewAnimation(final View view, int duration) { final int initialHeight = view.getMeasuredHeight(); Animation animation = new Animation() { @Override// w w w .java 2 s .c o m protected void applyTransformation(float interpolatedTime, Transformation t) { if (interpolatedTime == 1) { view.setVisibility(View.GONE); } else { view.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime); view.requestLayout(); } } @Override public boolean willChangeBounds() { return true; } }; animation.setDuration(duration); return animation; }
From source file:Main.java
public static void expand(final View v, final int targetHeight, int duration, Interpolator interpolator, final Animation.AnimationListener listener) { final int initialHeight = v.getMeasuredHeight(); Animation a = new Animation() { @Override/*from w ww . j a v a2s . c o m*/ protected void applyTransformation(float interpolatedTime, Transformation t) { v.getLayoutParams().height = initialHeight + (int) (targetHeight * interpolatedTime); v.requestLayout(); } @Override public boolean willChangeBounds() { return true; } }; a.setDuration(duration); if (interpolator != null) { a.setInterpolator(interpolator); } a.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { v.setLayerType(View.LAYER_TYPE_HARDWARE, null); if (listener != null) listener.onAnimationStart(animation); } @Override public void onAnimationEnd(Animation animation) { v.setLayerType(View.LAYER_TYPE_NONE, null); if (listener != null) listener.onAnimationEnd(animation); } @Override public void onAnimationRepeat(Animation animation) { if (listener != null) onAnimationRepeat(animation); } }); v.startAnimation(a); }
From source file:Main.java
public static void collapse(final View v, final int initialHeight, final int targetHeight, int duration, Animation.AnimationListener listener) { final int diffHeight = initialHeight - targetHeight; Animation a = new Animation() { @Override/*from www . j av a2 s . c o m*/ protected void applyTransformation(float interpolatedTime, Transformation t) { v.getLayoutParams().height = initialHeight - (int) (diffHeight * interpolatedTime); v.requestLayout(); } @Override public boolean willChangeBounds() { return true; } }; a.setDuration(duration); a.setInterpolator(new DecelerateInterpolator(2)); if (listener != null) { a.setAnimationListener(listener); } v.startAnimation(a); }
From source file:Main.java
/** * Creates an animation that rotates an {@link ImageView} * around the Y axis by 180 degrees and changes the image * resource shown when the view is rotated 90 degrees to the user. * * @param imageView the view to rotate. * @param drawableRes the drawable to set when the view * is rotated by 90 degrees. * @return an animation that will change the image shown by the view. *///from w ww . jav a 2 s.c o m @NonNull public static Animation createRotationTransitionAnimation(@NonNull final ImageView imageView, @DrawableRes final int drawableRes) { Animation animation = new Animation() { private boolean mSetFinalDrawable; @Override protected void applyTransformation(float interpolatedTime, Transformation t) { if (interpolatedTime < 0.5f) { imageView.setRotationY(90 * interpolatedTime * 2f); } else { if (!mSetFinalDrawable) { mSetFinalDrawable = true; imageView.setImageResource(drawableRes); } imageView.setRotationY((-90) + (90 * (interpolatedTime - 0.5f) * 2f)); } } }; animation.setDuration(300); animation.setInterpolator(new AccelerateDecelerateInterpolator()); return animation; }