Java 在android中使用不同的动画为许多不同的矢量绘制组设置动画

Java 在android中使用不同的动画为许多不同的矢量绘制组设置动画,java,android,animation,android-vectordrawable,animatedvectordrawable,Java,Android,Animation,Android Vectordrawable,Animatedvectordrawable,我正在尝试在gif上设置猫的动画: 我想出了如何制作爪子动画: res\drawable\animator_paws.xml <animated-vector xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/cat_default"> <target android:animati

我正在尝试在gif上设置猫的动画:

我想出了如何制作爪子动画:

res\drawable\animator_paws.xml

<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/cat_default">
    <target
        android:animation="@animator/animator_hide_element"
        android:name="right_paw_up">
    </target>
    <target
        android:animation="@animator/animator_show_element"
        android:name="right_paw_down">
    </target>
    <target
        android:animation="@animator/animator_show_element"
        android:name="left_paw_up_contour">
    </target>
    <target
        android:animation="@animator/animator_show_element"
        android:name="left_paw_point_up_point_one">
    </target>
    <target
        android:animation="@animator/animator_show_element"
        android:name="left_paw_point_up_point_two">
    </target>
    <target
        android:animation="@animator/animator_show_element"
        android:name="left_paw_point_up_point_three">
    </target>
    <target
        android:animation="@animator/animator_show_element"
        android:name="left_paw_point_up_point_inner">
    </target>
    <target
        android:animation="@animator/animator_hide_element"
        android:name="left_paw_down">
    </target>
</animated-vector>
<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/cat_default">
    <target
        android:animation="@animator/animator_show_element"
        android:name="right_paw_up">
    </target>
    <target
        android:animation="@animator/animator_hide_element"
        android:name="right_paw_down">
    </target>
    <target
        android:animation="@animator/animator_hide_element"
        android:name="left_paw_up_contour">
    </target>
    <target
        android:animation="@animator/animator_hide_element"
        android:name="left_paw_point_up_point_one">
    </target>
    <target
        android:animation="@animator/animator_hide_element"
        android:name="left_paw_point_up_point_two">
    </target>
    <target
        android:animation="@animator/animator_hide_element"
        android:name="left_paw_point_up_point_three">
    </target>
    <target
        android:animation="@animator/animator_hide_element"
        android:name="left_paw_point_up_point_inner">
    </target>
    <target
        android:animation="@animator/animator_show_element"
        android:name="left_paw_down">
    </target>
</animated-vector>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <objectAnimator
        android:duration="1"
        android:propertyName="fillAlpha"
        android:valueFrom="1"
        android:valueTo="0"
        android:valueType="floatType" />
    <objectAnimator
        android:duration="1"
        android:propertyName="strokeAlpha"
        android:valueFrom="1"
        android:valueTo="0"
        android:valueType="floatType" />
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <objectAnimator
        android:duration="1"
        android:propertyName="fillAlpha"
        android:valueFrom="0"
        android:valueTo="1"
        android:valueType="floatType" />
    <objectAnimator
        android:duration="1"
        android:propertyName="strokeAlpha"
        android:valueFrom="0"
        android:valueTo="1"
        android:valueType="floatType" />
</set>
我得到的是——猫按一下键

现在我想在视图创建后添加背景注释动画,但我不知道如何在不设置AnimatedVectorDrawable的情况下修改VectorDrawable的单独组。 安卓API提供了简单的方法吗? 是否有其他方法可以通过复杂的动画为svg设置动画? 非常感谢

我带着这只小猫去了那里,为了教育目的,我试着复制这个项目

 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View fragmentView = inflater.inflate(R.layout.fragment_blank, container, false);
        ImageView catImage = fragmentView.findViewById(R.id.cat_id);
        catImage.setOnClickListener(v -> {
            if (reversed) {
                catImage.setImageDrawable(requireContext().getDrawable(R.drawable.animator_paws_back));
                reversed = false;
            } else {
                catImage.setImageDrawable(requireContext().getDrawable(R.drawable.animator_paws));
                reversed = true;
            }
            Drawable drawable = catImage.getDrawable();
            ((Animatable) drawable).start();

        });
        return fragmentView;
    }