Android-如何在矢量图上实现中心比例动画

标签 android xml animation scale android-vectordrawable

我最近开始涉足矢量图像和动画。但是,一旦路径变形动画完成,我希望能够在所有方向上统一缩放我的图像。

我已经尝试尽可能地应用 pivotX 和 Y,但它似乎没有什么不同。

我怎样才能实现中心尺度而不是仅仅从左向右扩展?

test_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_gravity="center"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/test_image"
        android:layout_gravity="center"
        android:src="@drawable/animated_logo"
        android:layout_width="200dp"
        android:layout_height="200dp" />

</FrameLayout>

animated_logo.xml

<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/closed_logo" >
    <target
        android:animation="@anim/scale"
        android:name="logo"/>
</animated-vector>

scale.anim

<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
    android:duration="1500"
    android:propertyName="scaleX"
    android:valueFrom="1.0"
    android:valueTo="10"
    android:valueType="floatType"/>
<objectAnimator
    android:duration="1500"
    android:propertyName="scaleY"
    android:valueFrom="1.0"
    android:valueTo="10"
    android:valueType="floatType"/>

closed_logo.xml

    <?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:viewportWidth="75"
    android:viewportHeight="75"
    android:width="1000dp"
    android:height="1000dp">
    <group android:name="logo">
        <path
            android:name="box"
            android:fillColor="#DADADA"
            android:pathData="M65.5,54.4L11.1,65.5L0,11.1L54.4,0L65.5,54.4z"/>


    <path
            android:name="bottom_left"
            android:fillColor="#47A89C"
            android:pathData="M 7.1,22.2 l 15.2,36.0 l 10.4,-25.6 L 32.699997,32.6 L 7.1,22.2 L 7.1,22.2z" />

        <path
            android:name="top_left"
            android:fillColor="#564B74"
            android:pathData="M43.1,7.1L7.1,22.2l25.6,10.4L43.1,7.1z" />

        <path
            android:name="top_right"
            android:fillColor="#D2A219"
            android:pathData="M 22.3,58.2 L 58.3,43.0 l 0.0,0.0 L 32.7,32.6 L 22.3,58.2z" />

        <path
            android:name="bottom_right"
            android:fillColor="#BD6474"
            android:pathData="M 32.7,32.6 L 58.3,43.0 l 0.0,0.0 L 43.0,7.1 L 32.7,32.6z" />
    </group>
</vector>

最佳答案

我知道这个问题很老,但以防万一它对任何人都有帮助。

将 pivotX 和 pivotY 添加到要设置动画的组中。 所以对于你的情况,改变

  <group android:name="logo">

  <group android:name="logo" android:pivotX="37.5" android:pivotY="37.5">

关于Android-如何在矢量图上实现中心比例动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32741042/

相关文章:

Android:更改屏幕上的相机预览大小

android - 如何在 android 的 actionbar 中设置自定义 View ?

c# - C# 中的 Xml 序列化 - 根元素数组

javascript - Jquery 动画不工作

javascript - 是否可以为 Angular 2 的 ng-switch 设置动画

java - CustomEditText 的奇怪行为

android - 即使在 XML 中定义了大小,图像也不会调整大小 (Android Studio)

c# - 在 C# XML 中解析 XML 以获取特定内容

android - 如何重复 Android 动画

android - 使用 Parcelable 而不是序列化对象的好处