Wiktor
Wiktor

Reputation: 925

Android Scale Animation not smooth

I don't know how to create a <scale> animation on ImageView that works fine, i created one with Vector Drawable that works, but image one is not smooth at all, gif at the bottom:

<vector xmlns:android="http://schemas.android.com/apk/res/android"

android:width="24px"
android:height="24px"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
>

<group android:name="background"
    android:pivotX="12"
    android:pivotY="12">
    <path
        android:name="circle"
        android:fillColor="#F235"
        android:pathData="M12,12m-10,0a10,10 0,1 1,20 0a10,10 0,1 1,-20 0" />
</group>
</vector>

Animation:

<set xmlns:android="http://schemas.android.com/apk/res/android">

    <objectAnimator
        android:duration="400"
        android:propertyName="scaleX"
        android:valueFrom="1.0"
        android:valueTo="0.8"
        android:valueType="floatType"
        />

    <objectAnimator
        android:duration="400"
        android:propertyName="scaleY"
        android:valueFrom="1.0"
        android:valueTo="0.8"
        android:valueType="floatType"
        />

    <objectAnimator
        android:duration="400"
        android:startOffset="500"
        android:propertyName="scaleX"
        android:valueFrom="0.8"
        android:valueTo="1"
        android:valueType="floatType"
        />
    <objectAnimator
        android:duration="400"
        android:startOffset="500"
        android:propertyName="scaleY"
        android:valueFrom="0.8"
        android:valueTo="1"
        android:valueType="floatType"
        />

</set>

That's my image scale animation:

<set xmlns:android="http://schemas.android.com/apk/res/android">

    <scale
        android:duration="400"
        android:pivotX="50%"
        android:pivotY="50%"
        android:fromXScale="1.0"
        android:toXScale="0.8"
        android:fromYScale="1.0"
        android:toYScale="0.8"
        />

    <scale
        android:startOffset="500"
        android:duration="400"
        android:pivotX="50%"
        android:pivotY="50%"
        android:fromXScale="0.8"
        android:fromYScale="0.8"
        android:toYScale="1.0"
        android:toXScale="1.0" />


</set>

Blue one is Vector Drawable, Red one is ImageView animated with <scale>

I know it can be solved by deleting second <scale> and adding

android:repeatMode="reverse"
android:repeatCount="1"

to the first one, but i'd like to make it work with two <scale> commands

enter image description here

Upvotes: 0

Views: 1424

Answers (1)

atarasenko
atarasenko

Reputation: 1808

Your second animation should start with scale 1.0 and end with 1.25:

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:duration="400"
        android:pivotX="50%"
        android:pivotY="50%"
        android:fromXScale="1.0"
        android:toXScale="0.8"
        android:fromYScale="1.0"
        android:toYScale="0.8"
    />

    <scale
        android:startOffset="500"
        android:duration="400"
        android:pivotX="50%"
        android:pivotY="50%"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:toYScale="1.25"
        android:toXScale="1.25" />
</set>

Otherwise, scale 0.8 is applied instantly, without delay of 500ms. Related question

Upvotes: 2

Related Questions