【问题标题】:Android Scale Animation not smoothAndroid Scale Animation 不流畅
【发布时间】:2018-09-30 22:14:51
【问题描述】:

我不知道如何在 ImageView 上创建一个可以正常工作的 <scale> 动画,我使用 Vector Drawable 创建了一个可以正常工作的动画,但是一个图像根本不平滑,底部有 gif:

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

android:width="24px"
android:height="24px"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
>

<group android:name="background"
    android:pivotX="12"
    android:pivotY="12">
    <path
        android:name="circle"
        android:fillColor="#F235"
        android:pathData="M12,12m-10,0a10,10 0,1 1,20 0a10,10 0,1 1,-20 0" />
</group>
</vector>

动画:

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

    <objectAnimator
        android:duration="400"
        android:propertyName="scaleX"
        android:valueFrom="1.0"
        android:valueTo="0.8"
        android:valueType="floatType"
        />

    <objectAnimator
        android:duration="400"
        android:propertyName="scaleY"
        android:valueFrom="1.0"
        android:valueTo="0.8"
        android:valueType="floatType"
        />

    <objectAnimator
        android:duration="400"
        android:startOffset="500"
        android:propertyName="scaleX"
        android:valueFrom="0.8"
        android:valueTo="1"
        android:valueType="floatType"
        />
    <objectAnimator
        android:duration="400"
        android:startOffset="500"
        android:propertyName="scaleY"
        android:valueFrom="0.8"
        android:valueTo="1"
        android:valueType="floatType"
        />

</set>

这是我的图片缩放动画:

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

    <scale
        android:duration="400"
        android:pivotX="50%"
        android:pivotY="50%"
        android:fromXScale="1.0"
        android:toXScale="0.8"
        android:fromYScale="1.0"
        android:toYScale="0.8"
        />

    <scale
        android:startOffset="500"
        android:duration="400"
        android:pivotX="50%"
        android:pivotY="50%"
        android:fromXScale="0.8"
        android:fromYScale="0.8"
        android:toYScale="1.0"
        android:toXScale="1.0" />


</set>

蓝色的是Vector Drawable,红色的是ImageView 动画&lt;scale&gt;

我知道可以通过删除第二个&lt;scale&gt;并添加来解决

android:repeatMode="reverse"
android:repeatCount="1"

第一个,但我想让它与两个&lt;scale&gt; 命令一起工作

【问题讨论】:

  • 红色圆圈在视觉上比蓝色圆圈大。它最初是否有 scaleX=1 和 scaleY=1?
  • 你是对的,但我认为这是因为圆形的矢量可绘制看起来像那样,我实际上不知道如何使它像红色那样理想地适合,但我什么也没做否则红色圆圈,那么比例怎么可能不是 1 ? Screen herecircle here

标签: android animation android-animation


【解决方案1】:

您的第二个动画应该以缩放1.0 开头并以1.25 结尾:

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:duration="400"
        android:pivotX="50%"
        android:pivotY="50%"
        android:fromXScale="1.0"
        android:toXScale="0.8"
        android:fromYScale="1.0"
        android:toYScale="0.8"
    />

    <scale
        android:startOffset="500"
        android:duration="400"
        android:pivotX="50%"
        android:pivotY="50%"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:toYScale="1.25"
        android:toXScale="1.25" />
</set>

否则,缩放0.8 会立即应用,没有 500 毫秒的延迟。 Related question

【讨论】:

  • 哦,原来如此,我必须将每个&lt;scale&gt; 当作单独的动画,非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-25
  • 2014-10-27
  • 1970-01-01
  • 2019-06-02
  • 1970-01-01
相关资源
最近更新 更多