如果有人点击,我想绘制一个可绘制的动画。“开始绘图”是指向底部的箭头。单击后,它将更改为指向顶部的箭头。
我的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"
发布于 2019-11-20 06:58:46
用这个:
app:srcCompat="@drawable/animated_vector"
而不是:
android:src="@drawable/animated_vector"
https://stackoverflow.com/questions/58943324
复制相似问题