Android ViewPropertyAnimator does not scale at the same time

I am trying to use ViewPropertyAnimator to scale the view (undefined ProgressBar) every time I click the button.

loadingCircle.animate().scaleY(1.5f).scaleX(1.5f).setDuration(100f); 

I have an animatorListener that returns to normal on an AnimationEnd:

 loadingCircle.animate().scaleY(1.0f).scaleX(1.0f).setDuration(100f); 

Nothing complicated. However, it does not seem to always scale both x and y always.

Usually he does it right the first time, sometimes the second time. When it does not work, it only enlivens the last operation in the chain. If it is scaleX, it will scale only X. If I change it, it will scale only Y.

The documentation for scaleX and scaleY says:

Animations already running in the property will be canceled.

However, I thought that ViewPropertyAnimator could be attached, and this comment applies only to new animations (on a different line of code). Am I doing something wrong, or have I found a mistake?

I am running Android 4.2.2 on GalaxyS4. Stock ROM, but rooted. If that matters.

+8
android animation view scale
source share
3 answers

I think this is really a mistake. I worked on this using ObjectAnimator instead of ViewPropertyAnimator to get the same result. So yours looks something like this:

 ObjectAnimator animX = ObjectAnimator.ofFloat(loadingCircle, "scaleX", 1.0f); ObjectAnimator animY = ObjectAnimator.ofFloat(loadingCircle, "scaleY", 1.0f); AnimatorSet animSetXY = new AnimatorSet(); animSetXY.playTogether(animX, animY); animSetXY.start(); 

Source: http://developer.android.com/guide/topics/graphics/prop-animation.html#view-prop-animator

+6
source share

Reading through the source code the behavior that you describe makes sense in design. When you add an animation, it starts on the next runloop / whenever possible. Sometimes you can get both animations there before it happens, sometimes you won't.

If you tell him not to start the animation right away, you will have enough time to add all your animations. This is obviously a bit of a hack.

Perhaps you could try something like this:

 loadingCircle.animate() .setStartDelay(1000) //prevent the animation from starting .scaleY(1.5f) .scaleX(1.5f) .setDuration(100f) .setStartDelay(0) .start(); 
+2
source share
 AnimatorSet set = new AnimatorSet(); set.setInterpolator(new AccelerateInterpolator()); set.setDuration(100l); view.setPivotX(halfWidth); view.setPivotY(helfHeight); set.play(ObjectAnimator.ofFloat(view, View.SCALE_X, 0f, 1f)) .with(ObjectAnimator.ofFloat(hRippleAdd, View.SCALE_Y, 0f, 1f)); set.start(); 
0
source share

All Articles