微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在android中使用不同的动画对许多不同的VectorDrawable组进行动画处理

如何解决在android中使用不同的动画对许多不同的VectorDrawable组进行动画处理

我正在尝试为 gif 中的猫制作动画:

cat is slapping keyboard

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

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>

res\drawable-v24\animator_paws_back.xml

<?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>

res/animator/animator_hide_element.xml

<?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>

res/animator/animator_show_element.xml

<?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>

然后我添加了我的 Fragment ImageView 并以编程方式将其更改为 Drawable(我不喜欢但没有找到更好的方法来做到这一点)。

 @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;
    }

我所拥有的 - 猫会在点击时拍打按键。

enter image description here

现在我想在创建视图后添加背景注释动画,但我无法理解如何在不设置 AnimatedVectorDrawable 的情况下修改分离的 VectorDrawable 组。 android API 是否提供任何简单的方法来做到这一点? 有没有其他方法可以用复杂的动画制作 svg 动画? 非常感谢。

我把这只小猫带到那里 https://hostrider.com/ 并尝试复制该项目用于教育目的

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。