Reputation: 63
I have this animation where it scales up a little bit, then scales back down to the original size. But as its scaling back down to its original size, it slowly scales down, the its suddenly at its original size. And no, its not the accelerate decelerate interpolator, i also tried the linear one and it did the same.
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:startOffset="1000"
android:shareInterpolator="true">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="1000" />
<scale
android:duration="1000"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="25%p"
android:pivotY="75%p"
android:toXScale="1.1"
android:toYScale="1.1" />
<set
android:startOffset="500">
<scale
android:duration="1000"
android:fromXScale="1.1"
android:fromYScale="1.1"
android:pivotX="25%p"
android:pivotY="75%p"
android:toXScale="1.0"
android:toYScale="1.0" />
</set>
</set>
Upvotes: 4
Views: 1356
Reputation: 491
Your first scale animations duration is 1000. The second one starts after 500ms. So they are interfering. Maybe that's your problem. You could try to set the second animations start offset to 1000. If this doesn't help you could take a look at Animation.fillAfter()
EDIT: This works
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:shareInterpolator="true"
android:startOffset="1000">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="1000" />
<scale
android:duration="1000"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="25%p"
android:pivotY="75%p"
android:toXScale="1.1"
android:toYScale="1.1" />
<scale
android:duration="1000"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="25%p"
android:pivotY="75%p"
android:startOffset="1000"
android:toXScale="0.9"
android:toYScale="0.9" />
</set>
And you don't have to have a second set inside the set, just add the startOffset directly to the scale animation.
And I just realised, that the second scale has to use 1.0 and 0.9 instead of 1.1 and 1.0. Because it takes the percentage of the current size, not the original size.
Upvotes: 3
Reputation: 113
1) I think you can do it like that. The position and scale... vs properties will not turned the original.
view.animate()
.setDuration(1000)
.alpha(1)
.x(view.getPivotX() * 25 / 100)
.y(view.getPivotX() * 25 / 100)
.scaleX(1.1f)
.scaleY(1.1f)
.start();
view.animate()
.setStartDelay(1000)
.setDuration(1000)
.scaleX(1f)
.scaleY(1f)
.start();
2) Your animation's duration 1000ms and your second delay is 500. It may be causing the problem.
Upvotes: 1