Venator85
Venator85

Reputation: 10335

Specify starting values for ViewPropertyAnimator

Using ObjectAnimators, optionally with PropertyValuesHolders, it is possible to specify starting and ending values for the animated property:

ObjectAnimator animX = ObjectAnimator.ofFloat(myView, "x", 20f, 50f);
ObjectAnimator animY = ObjectAnimator.ofFloat(myView, "y", 30f, 100f);
AnimatorSet animSetXY = new AnimatorSet();
animSetXY.playTogether(animX, animY);
animSetXY.start();

PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("x", 20f, 50f);
PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("y", 30f, 100f);
ObjectAnimator.ofPropertyValuesHolder(myView, pvhX, pvyY).start();

How can I achieve the same animation with ViewPropertyAnimators? The syntax doesn't seem to support starting values, assuming they are equals to the values the view has at animation start:

myView.animate().x(50f).y(100f); //Where do I put starting values??

Thanks ;)

Upvotes: 4

Views: 2568

Answers (1)

Andy McSherry
Andy McSherry

Reputation: 4725

If you're going to use ViewPropertyAnimator, your Views need to be at the start positions before the animation starts.

Upvotes: 4

Related Questions