为什么我的AnimationSet没有正确执行?

时间:2014-01-14 16:53:31

标签: android android-layout android-animation

问题

当我尝试使用此缩小然后放大动画为TextView设置动画时,它无法正确缩放。 我的TextView将立即缩放到50%的大小,然后,在此之后,动画将开始播放,当它完成时,TextView的大小将约为其初始大小的50%,之后就是它将返回100%。

这是动画

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

    <!-- Zoom Out -->
    <scale
        android:duration="750"
        android:fromXScale="1"
        android:fromYScale="1"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="0.6"
        android:toYScale="0.6">
    </scale>

    <!-- Zoom In -->
    <scale
        android:duration="750"
        android:startOffset="750"
        android:fromXScale="0.6"
        android:fromYScale="0.6"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="1"
        android:toYScale="1">
    </scale>
</set>

我尝试了什么

我试着查看SetAnimation和ScaleAnimation的文档,但没有发现任何有用的东西来解决我的问题。

我尝试改变一些值,我将在这里描述它是如何影响动画的。 我将谈论大小如2.0和0.6,而不是夫妻,因为在我的实验中,我总是将XScale等于fromsccale和toXScale等于tosccale。所以,

如果我从2.0到0.6,然后从0.6到2.0,则动画正确执行(它将从文本视图的实际大小开始,没有2x,它将返回实际大小) 如果我从2.0到1.0,然后从1.0到2.0,动画将从2.0开始..转到1.0并返回到2.0 ..然后,TextView将立即返回其原始大小。

修改

我只是尝试了另一件事。我做了与下面动画相反的操作,即放大后缩小动画

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

    <!-- Zoom In -->
    <scale
        android:duration="750"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="1.5"
        android:toYScale="1.5">
    </scale>

    <!-- Zoom Out -->
    <scale
        android:duration="750"
        android:startOffset="750"
        android:fromXScale="1.5"
        android:fromYScale="1.5"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="1.0"
        android:toYScale="1.0">
    </scale>
</set>

行为已经发生,只是这次反向:视图立即放大动画执行并立即缩小到原始状态。


问题

如何正确执行动画,值为fromXScale=1.0 --> toXScale=0.6 --> toXScale=1.0fromYScale=1.0 --> toYScale=0.6 --> toYScale=1

为什么我的代码无效?

0 个答案:

没有答案
相关问题