List of usage examples for android.animation ValueAnimator getAnimatedValue
public Object getAnimatedValue()
ValueAnimator
when there is just one property being animated. From source file:Main.java
public static void animateHeight(final View view, int from, int to, int duration) { boolean expanding = to > from; ValueAnimator anim = ValueAnimator.ofInt(from, to); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override/* w w w.j a v a 2s.c o m*/ public void onAnimationUpdate(ValueAnimator valueAnimator) { int val = (Integer) valueAnimator.getAnimatedValue(); ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); layoutParams.height = val; view.setLayoutParams(layoutParams); } }); anim.setDuration(duration); anim.start(); view.animate().alpha(expanding ? 1 : 0).setDuration(duration / 2).start(); }
From source file:Main.java
/** * Update alpha/*from w w w . ja v a 2 s.c o m*/ */ public static void updateAlpha(final View view, float fromValue, float toValue) { ValueAnimator animator = ValueAnimator.ofFloat(fromValue, toValue); animator.setDuration(150); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { float animatedValue = (float) valueAnimator.getAnimatedValue(); view.setAlpha(animatedValue); } }); animator.start(); }
From source file:Main.java
public static void startScaleAnime(final View view, float newScale, Animator.AnimatorListener listener) { ValueAnimator anime = ValueAnimator.ofFloat(view.getScaleX(), newScale); anime.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override//from ww w .j a v a2 s . co m public void onAnimationUpdate(ValueAnimator animation) { float s = Float.parseFloat(animation.getAnimatedValue().toString()); view.setScaleX(s); view.setScaleY(s); } }); if (listener != null) { anime.addListener(listener); } anime.setDuration(mAnimeDuration); anime.start(); }
From source file:Main.java
static void changeViewLeftPadding(final View view, int fromMargin, int toMargin) { ValueAnimator animator = ValueAnimator.ofFloat(fromMargin, toMargin); animator.setDuration(3000);//ww w. j a v a 2 s . co m animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { float animatedValue = (float) valueAnimator.getAnimatedValue(); view.setPadding((int) animatedValue, view.getPaddingTop(), view.getPaddingRight(), view.getPaddingBottom()); view.requestLayout(); } }); animator.start(); }
From source file:Main.java
public static void changeTextSize(final TextView textView, float from, float to) { ValueAnimator textSizeChangeAnimator = ValueAnimator.ofFloat(from, to); textSizeChangeAnimator.setDuration(150); textSizeChangeAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override//from w w w . jav a2 s . co m public void onAnimationUpdate(ValueAnimator valueAnimator) { textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) valueAnimator.getAnimatedValue()); } }); textSizeChangeAnimator.start(); }
From source file:Main.java
static void changeTextSize(final TextView textView, float from, float to) { ValueAnimator textSizeChangeAnimator = ValueAnimator.ofFloat(from, to); textSizeChangeAnimator.setDuration(150); textSizeChangeAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override/*from w w w. j av a 2 s. c o m*/ public void onAnimationUpdate(ValueAnimator valueAnimator) { textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) valueAnimator.getAnimatedValue()); } }); textSizeChangeAnimator.start(); }
From source file:Main.java
private static ValueAnimator slideAnimator(int start, int end, final View summary) { ValueAnimator animator = ValueAnimator.ofInt(start, end); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override/* w w w .j a v a 2 s . c o m*/ public void onAnimationUpdate(ValueAnimator valueAnimator) { //Update Height int value = (Integer) valueAnimator.getAnimatedValue(); ViewGroup.LayoutParams layoutParams = summary.getLayoutParams(); layoutParams.height = value; summary.setLayoutParams(layoutParams); } }); return animator; }
From source file:Main.java
@SuppressWarnings("deprecation") public static void clipDrawable(final View image, Drawable drawable, boolean isActivated) { if (drawable == null) { return;/*from w w w .ja v a2 s. co m*/ } if (isActivated) { final ClipDrawable scaleDrawable = new ClipDrawable(drawable, Gravity.CENTER, ClipDrawable.HORIZONTAL | ClipDrawable.VERTICAL); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { image.setBackground(scaleDrawable); } else { image.setBackgroundDrawable(scaleDrawable); } image.setBackgroundDrawable(scaleDrawable); ValueAnimator animator = ValueAnimator.ofInt(0, 10000); animator.setDuration(200); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { scaleDrawable.setLevel((Integer) animation.getAnimatedValue()); } }); animator.start(); } else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { image.setBackground(null); } else { image.setBackgroundDrawable(null); } } }
From source file:Main.java
private static Animator createFade(final View targetView, int startAlpha, int endAlpha) { ValueAnimator a = ValueAnimator.ofFloat(startAlpha, endAlpha); a.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override// www . j a va2s . c om public void onAnimationUpdate(ValueAnimator valueAnimator) { targetView.setAlpha((float) valueAnimator.getAnimatedValue()); } }); return a; }
From source file:Main.java
public static void dimBackground(final float from, final float to, Activity context) { final Window window = context.getWindow(); ValueAnimator valueAnimator = ValueAnimator.ofFloat(from, to); valueAnimator.setDuration(500);//from w ww .j av a 2s . co m valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { WindowManager.LayoutParams params = window.getAttributes(); params.alpha = (Float) animation.getAnimatedValue(); window.setAttributes(params); } }); valueAnimator.start(); }