Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: how to use ValueAnimator

I want to do a translate animation using this following

public static void move(TextView view){      ValueAnimator va = ValueAnimator.ofFloat(0f, 3f);     int mDuration = 3000; //in millis     va.setDuration(mDuration);     va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {         public void onAnimationUpdate(ValueAnimator animation) {          }     });     va.setRepeatCount(5);     va.start(); } 

But I don't know how to use onAnimationUpdate method.

Can anyone help please?

like image 905
Lionel Messi Avatar asked Nov 23 '15 11:11

Lionel Messi


1 Answers

If you really, really, really want to use ValueAnimator for animating translation of the View you can do it this way (finishing your example, assuming you meant translationX.

Bare in mind that you're animating translation from 0px to 3px, so you probably won't see much difference.

fun move(view: TextView) {   val va = ValueAnimator.ofFloat(0f, 3f)   va.duration = 3000 //in millis   va.addUpdateListener { animation -> view.translationX = animation.animatedValue as Float }   va.repeatCount = 5   va.start() } 
like image 155
Bartek Lipinski Avatar answered Oct 05 '22 15:10

Bartek Lipinski