anthony anthony - 2 months ago 15
Android Question

Android : smooth zoom in then zoom out animations

I have this animation to do a zoom in THEN a zoom out on an ImageView:

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator" android:fillAfter="true">
<scale
android:duration="200"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.3"
android:toYScale="1.3"/>
<scale
android:duration="300"
android:fromXScale="1.3"
android:fromYScale="1.3"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0"
android:toYScale="0"/>




But the result is not really smooth espacially the zoom in.

Thanks for your help!

Answer

Delay starting zoom out animation adding:

android:startOffset="200"

and start zoom out animation from scale 1:

android:fromXScale="1" android:fromYScale="1"

complete code:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_interpolator" android:fillAfter="true">
<scale
    android:duration="200"
    android:fromXScale="1"
    android:fromYScale="1"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="2"
    android:toYScale="2"/>
<scale
    android:startOffset="200"
    android:duration="300"
    android:fromXScale="1"
    android:fromYScale="1"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="0"
    android:toYScale="0"/>
</set>