Scale Animation Causes View to shorten before start of animation

不打扰是莪最后的温柔 提交于 2020-01-16 05:19:08

问题


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.


回答1:


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>


来源:https://stackoverflow.com/questions/26596304/scale-animation-causes-view-to-shorten-before-start-of-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!