我在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所示。这很奇怪,因为fromXScale
和fromYScale
从1.0
开始,所以我期望尺寸会逐渐变化而不是跳跃。
如果我删除第二组动画并保留如下代码,则>]
<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,如下所示。
为什么大小会增加?
我在这里关注view.animation示例https://developer.android.com/guide/topics/graphics/view-animation并遇到一些奇怪的问题。为了说明这个问题,我从...
显然,我们需要先将第二组fromXScale
和fromYScale
设置为1.0
的代码。