List of usage examples for android.view.animation Animation setDuration
public void setDuration(long durationMillis)
From source file:Main.java
public static Animation collapse(final View v, int duration, boolean startAnim) { //check if view already gone if (v.getVisibility() == View.GONE) return null; final int initialHeight = v.getMeasuredHeight(); Animation a = new Animation() { @Override//from www . j av a 2s. c o m protected void applyTransformation(float interpolatedTime, Transformation t) { if (interpolatedTime == 1) { v.setVisibility(View.GONE); } else { v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime); v.requestLayout(); } } @Override public boolean willChangeBounds() { return true; } }; a.setDuration(duration); if (startAnim) v.startAnimation(a); return a; }
From source file:Main.java
public static void collapse(final ViewGroup v) { final int initialHeight = v.getMeasuredHeight(); Animation a = new Animation() { @Override//from ww w. ja va 2 s. c o m protected void applyTransformation(float interpolatedTime, Transformation t) { if (interpolatedTime == 1) { v.setVisibility(View.GONE); } else { v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime); v.setAlpha(1 - interpolatedTime); v.requestLayout(); } } @Override public boolean willChangeBounds() { return true; } }; a.setDuration((int) (initialHeight / v.getContext().getResources().getDisplayMetrics().density)); 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 w w .j a v a2 s . c om*/ @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; }
From source file:Main.java
public static Animation getExpandViewAnimation(final View view, int duration) { view.measure(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); final int targetHeight = view.getMeasuredHeight(); view.getLayoutParams().height = 0;/*from w w w . j av a 2 s .c om*/ view.setVisibility(View.VISIBLE); Animation animation = new Animation() { @Override protected void applyTransformation(float interpolatedTime, Transformation t) { view.getLayoutParams().height = interpolatedTime == 1 ? RelativeLayout.LayoutParams.WRAP_CONTENT : (int) (targetHeight * interpolatedTime); view.requestLayout(); } @Override public boolean willChangeBounds() { return true; } }; // 1dp/ms // animation.setDuration((int) (targetHeight / // view.getContext().getResources().getDisplayMetrics().density)); animation.setDuration(duration); return 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// www. jav a 2 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:nkarasch.repeatingreminder.gui.AlertView.java
private static void expandView(final View view) { view.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); final int targetHeight = view.getMeasuredHeight(); view.getLayoutParams().height = 0;/*from w w w .j a v a 2 s .c om*/ view.setVisibility(View.VISIBLE); Animation animation = new Animation() { @Override protected void applyTransformation(float interpolatedTime, Transformation t) { view.getLayoutParams().height = interpolatedTime == 1 ? ViewGroup.LayoutParams.WRAP_CONTENT : (int) (targetHeight * interpolatedTime); view.requestLayout(); } @Override public boolean willChangeBounds() { return true; } }; animation.setDuration((int) (targetHeight / view.getContext().getResources().getDisplayMetrics().density)); view.startAnimation(animation); }
From source file:nkarasch.repeatingreminder.gui.AlertView.java
private static void collapseView(final View view) { final int initialHeight = view.getMeasuredHeight(); Animation animation = new Animation() { @Override/*from w w w . ja v a 2 s . co m*/ protected void applyTransformation(float interpolatedTime, Transformation transformation) { 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((int) (initialHeight / view.getContext().getResources().getDisplayMetrics().density)); view.startAnimation(animation); }
From source file:org.sufficientlysecure.keychain.ui.CreateSecurityTokenWaitFragment.java
/** * hack from http://stackoverflow.com/a/11253987 *//*from w w w . ja v a 2 s . co m*/ @Override public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) { if (sDisableFragmentAnimations) { Animation a = new Animation() { }; a.setDuration(0); return a; } return super.onCreateAnimation(transit, enter, nextAnim); }
From source file:com.benefit.buy.library.http.query.callback.BitmapAjaxCallback.java
private static void setBmAnimate(ImageView iv, Bitmap bm, Bitmap preset, int fallback, int animation, float ratio, float anchor, int source) { bm = filter(iv, bm, fallback);//ww w .j a v a2s . c o m if (bm == null) { iv.setImageBitmap(null); return; } Drawable d = makeDrawable(iv, bm, ratio, anchor); Animation anim = null; if (fadeIn(animation, source)) { if (preset == null) { anim = new AlphaAnimation(0, 1); anim.setInterpolator(new DecelerateInterpolator()); anim.setDuration(FADE_DUR); } else { Drawable pd = makeDrawable(iv, preset, ratio, anchor); Drawable[] ds = new Drawable[] { pd, d }; TransitionDrawable td = new TransitionDrawable(ds); td.setCrossFadeEnabled(true); td.startTransition(FADE_DUR); d = td; } } else if (animation > 0) { anim = AnimationUtils.loadAnimation(iv.getContext(), animation); } iv.setImageDrawable(d); if (anim != null) { anim.setStartTime(AnimationUtils.currentAnimationTimeMillis()); iv.startAnimation(anim); } else { iv.setAnimation(null); } }
From source file:com.webianks.library.ShowHideAnimation.java
public void animateIn(RelativeLayout view) { view.setVisibility(View.VISIBLE); Animation anim = AnimationUtils.loadAnimation(view.getContext(), R.anim.pop_in); anim.setDuration(300L); anim.setInterpolator(INTERPOLATOR);//from w w w .j a va 2 s. co m view.startAnimation(anim); }