【问题标题】:AnimatedVectorDrawable throws UnsupportedOperationExceptionAnimatedVectorDrawable 抛出 UnsupportedOperationException
【发布时间】:2020-01-02 03:17:02
【问题描述】:

如果有人点击,我想为 drawable 设置动画。 Start drawable 是一个指向底部的箭头。点击后会变成指向顶部的箭头。

我的 xml 文件

anim_down_to_top.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
        android:duration="1000"
        android:propertyName="downToUp"
        android:valueFrom="M7.41,7.84L12,12.42l4.59,-4.58L18,9.25l-6,6 -6,-6z"
        android:valueTo="M7.41,15.41L12,10.83l4.59,4.58L18,14l-6,-6 -6,6z"
        android:valueType="pathType"/>

animated_vector.xml

<animated-vector xmlns:android="http://schemas.android.com/apk/res/android" 
    android:drawable="@drawable/ic_keyboard_arrow_down_black_24dp">
<target
        android:animation="@animator/anim_down_to_up"
        android:name="down"/>
</animated-vector>

ic_keyboard_arrow_down_black_24dp.xml

<vector android:height="24dp" 
    android:tint="#05164D"
    android:viewportHeight="24.0" 
    android:viewportWidth="24.0"
    android:width="24dp" 
    xmlns:android="http://schemas.android.com/apk/res/android">
<path android:name="down" 
        android:fillColor="#FF000000" 
        android:pathData="M7.41,7.84L12,12.42l4.59,-4.58L18,9.25l-6,6 -6,-6z"/>
</vector>

和布局xml

<androidx.appcompat.widget.AppCompatImageButton
                        android:id="@+id/expandDepButton"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/animated_vector"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />

要开始动画,代码如下所示

AppCompatImageButton expandDepField = view.findViewById(R.id.expandDepButton);

expandDepField.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AppCompatImageButton btn = (AppCompatImageButton) v;
            AnimatedVectorDrawable anim = (AnimatedVectorDrawable) btn.getDrawable();

            anim.start();

        }
    });

但我收到以下异常

java.lang.UnsupportedOperationException: Unsupported type: class android.util.PathParser$PathData. Only float, int or PathData value is supported for Paths.

请帮帮我,我做错了什么?

编辑:问题已解决 同时我解决了这个问题。我错过了将 anim_down_to_top.xml 中的属性名设置为“pathData”,如下所示

android:propertyName="pathData"

【问题讨论】:

    标签: java android xml animation


    【解决方案1】:

    使用这个:

    app:srcCompat="@drawable/animated_vector"
    

    代替:

    android:src="@drawable/animated_vector"
    

    【讨论】:

      猜你喜欢
      • 2013-02-26
      • 2022-01-22
      • 2014-01-30
      • 1970-01-01
      • 2016-02-24
      • 2014-09-13
      • 2011-11-05
      • 2014-11-28
      • 2014-09-21
      相关资源
      最近更新 更多