Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scaling animation on an already scaled view

I'm animating an ImageView using the following scale animations:

<?xml version="1.0" encoding="utf-8"?>

<set    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shareInterpolator="false">
    <scale
        android:interpolator="@android:anim/accelerate_interpolator"
        android:fromXScale="1.0"
        android:toXScale="2.0"
        android:fromYScale="1.0"
        android:toYScale="2.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="1000" />

    <scale
        android:interpolator="@android:anim/accelerate_interpolator"
        android:fromXScale="2.0"
        android:toXScale="0.0"
        android:fromYScale="2.0"
        android:toYScale="0.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:startOffset="1000"
        android:duration="1000" />

    <rotate xmlns:android="http://schemas.android.com/apk/res/android"
        android:fromDegrees="0"
        android:interpolator="@android:anim/linear_interpolator"
        android:toDegrees="360" android:pivotX="50%" android:pivotY="50%"
        android:repeatCount="3"
        android:duration="800" android:startOffset="0" />
</set>

But the problem is that the ImageView is already scaled by the layout, when the first animation begins. This leads to a noticeable jump in size, when the first animation sets the scale to 1.0 .

Is there any way of telling the animation that it should start from the actual size of a view in the layout? I also tried working with percentages, which produced the same effect.

like image 324
Herr von Wurst Avatar asked Nov 02 '22 15:11

Herr von Wurst


1 Answers

From what I understand from your query is that you wanna make your animation smoother, by avoiding the obviously noticeable scale animation at the beginning. I think minimizing the 'from scale' in the first scale would help you avoid the jump, maybe something like this would help:

<?xml version="1.0" encoding="utf-8"?>

<scale
    android:duration="1000"
    android:fromXScale="0.5"
    android:fromYScale="0.5"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="1.0"
    android:toYScale="1.0" />
<scale
    android:duration="1000"
    android:fromXScale="1.0"
    android:fromYScale="1.0"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:pivotX="50%"
    android:pivotY="50%"
    android:startOffset="1000"
    android:toXScale="1.0"
    android:toYScale="1.0" />

<rotate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="800"
    android:fromDegrees="0"
    android:interpolator="@android:anim/linear_interpolator"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="3"
    android:startOffset="0"
    android:toDegrees="360" />

Sorry to keep you waiting; try something like this:

<?xml version="1.0" encoding="utf-8"?>

<scale
    android:duration="400"
    android:fromXScale="1"
    android:fromYScale="1"
    android:pivotX="20%"
    android:pivotY="20%"
    android:repeatCount="1"
    android:repeatMode="reverse"
    android:toXScale="1.1"
    android:toYScale="1.1" />

like image 149
Sathya Avatar answered Nov 09 '22 16:11

Sathya