Igor
Igor

Reputation: 1331

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 to change 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 is appearing, but not animated.

What am I missing?

Edit:

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

Upvotes: 4

Views: 4683

Answers (1)

user
user

Reputation: 87064

What am I missing?

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

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

or if you're targeting ICS you could use:

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

Upvotes: 6

Related Questions