liquidpenguins
liquidpenguins

Reputation: 994

Scale Animation Causes View to shorten before start of animation

So I have this scaling animation and what it's supposed to do is scale the view to 70% of the full height, and then scale it back to the original size. I have two scale animations with different startOffsets.

The problem I'm having with this is the view scales before the animations even start. So when the animations start, they work with the already-shortened-scaled view.

Here is my animation xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true"
    android:interpolator="@android:anim/linear_interpolator" >
    <scale
        android:duration="300"
        android:fillAfter="true"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:startOffset="200"
        android:toXScale="1.0"
        android:toYScale="0.7"
        />
    <scale
        android:duration="300"
        android:fillAfter="true"
        android:fromXScale="1.0"
        android:fromYScale="0.7"
        android:startOffset="1000"
        android:toXScale="1.0"
        android:toYScale="1.0"
        />
</set>

And here is how I call this animation:

mScaleTop = AnimationUtils.loadAnimation(this, R.anim.scale_top);
mTopView.startAnimation(mScaleTop);

Any ideas? Thanks for reading.

Upvotes: 1

Views: 629

Answers (1)

MohamedZaatari
MohamedZaatari

Reputation: 434

depending on @pskink notice in comments

if your animation had a cycle mode you can only set android:interpolator property to @android:anim/cycle_interpolator" so you can use only the first stage and then will return to orginal status...

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="@android:anim/cycle_interpolator" >

<scale
    android:duration="300"
    android:fillAfter="true"
    android:fromXScale="1.0"
    android:fromYScale="1.0"
    android:startOffset="200"
    android:toXScale="1.0"
    android:toYScale="0.7" />

</set>

Otherwise if you want to use linear_interpolator you have to scale height from also 1.0 and not from 0.7 because the 1.0 indicate to current status

android:fromYScale="1.0" meaning that 100% of current status and = 70% of orginal status...

so you have to scale height android:fromYScale="1.0" to android:fromXScale="1.42"

because: android:fromYScale="1.0"=70% from orginal size you have to add 42% of 70 to equal 100% of full orginal height....

 <?xml version="1.0" encoding="utf-8"?>
 <set xmlns:android="http://schemas.android.com/apk/res/android"
 android:interpolator="@android:anim/linear_interpolator" >

<scale
    android:duration="300"
    android:fillAfter="true"
    android:fromXScale="1.0"
    android:fromYScale="1.0"
    android:startOffset="200"
    android:toXScale="1.0"
    android:toYScale="0.7"
    />
<scale
    android:duration="300"
    android:fillAfter="true"
    android:fromXScale="1.0"
    android:fromYScale="1.0"
    android:startOffset="1000"
    android:toXScale="1.0"
    android:toYScale="1.42"
    />
</set>

Upvotes: 4

Related Questions