Android View.Animation大小在与其他动画集一起使用时会跳转。为什么?

问题描述 投票:0回答:1

我在https://developer.android.com/guide/topics/graphics/view-animation处遵循view.animation示例,并遇到了一些奇怪的问题。

为了说明这个问题,我使用以下相同的代码将持续时间从700ms延长到2000ms。

<set android:shareInterpolator="false"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:fromXScale="1.0"
        android:toXScale="1.4"
        android:fromYScale="1.0"
        android:toYScale="1.4"
        android:pivotX="50%"
        android:pivotY="50%"
        android:fillAfter="false"
        android:duration="2000" />
    <set android:interpolator="@android:anim/decelerate_interpolator">
        <scale
            android:fromXScale="1.4"
            android:toXScale="0.0"
            android:fromYScale="1.4"
            android:toYScale="0.0"
            android:pivotX="50%"
            android:pivotY="50%"
            android:startOffset="2000"
            android:duration="400"
            android:fillBefore="false" />
        <rotate
            android:fromDegrees="0"
            android:toDegrees="-45"
            android:toYScale="0.0"
            android:pivotX="50%"
            android:pivotY="50%"
            android:startOffset="2000"
            android:duration="400" />
    </set>
</set>

您注意到初始动画,Hello World!大小在开始时就跳了起来,如下面的gif所示。这很奇怪,因为fromXScalefromYScale1.0开始,所以我期望尺寸会逐渐变化而不是跳跃。

Unexpcted jumped in size at the start

如果我删除第二组动画并保留如下代码,则>]

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

然后动画看起来很平滑,将其尺寸从1.0相应地增加到1.4,如下所示。

Expected behavior

为什么大小会增加?

我在这里关注view.animation示例https://developer.android.com/guide/topics/graphics/view-animation并遇到一些奇怪的问题。为了说明这个问题,我从...

android
1个回答
0
投票

显然,我们需要先将第二组fromXScalefromYScale设置为1.0的代码。

© www.soinside.com 2019 - 2024. All rights reserved.