Android ValueAnimator not working

I have this working code in my AsyncTasks class.

protected void onProgressUpdate(Object... values) { View view = (View) values[0]; view_group.addView(view); view.animate().y(500).setDuration(1000); } 

I tried changing the code to this:

 protected void onProgressUpdate(Object... values) { View view = (View) values[0]; view_group.addView(view); ValueAnimator va = ObjectAnimator.ofInt(view, "y", 500); va.setDuration(1000); va.start(); } 

The view appears, but is not animated.

What am I missing?

Edit:

I also tried to put the ValueAnimator code inside the AnimatorListener (with different coordinates, of course), so it will run after the first animation finishes, but that didn't work.

+4
source share
1 answer

What am I missing?

x and y are float values, not int , so use:

 ValueAnimator va = ObjectAnimator.ofFloat(view, "y", 500); 

or if you target ICS , you can use:

 ValueAnimator va = ObjectAnimator.ofFloat(view, View.Y, 500); 
+5
source

Source: https://habr.com/ru/post/1496603/


All Articles