在android中用不同的动画制作许多不同组的矢量图

pinkon5k  于 2021-07-09  发布在  Java
关注(0)|答案(0)|浏览(244)

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

我想出了如何制作爪子的动画:
res\drawable\animator\u 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\u paws\u 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\u hide\u 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\u show\u 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>

然后我在fragmentimageview中添加了它,并以编程方式更改了它的可绘制性(我不喜欢这样,但没有找到更好的方法)。

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

我得到的-猫按一下键。

现在我想在视图创建后添加背景注解动画,但是我不知道如何在不设置animatedvectordrawable的情况下修改vectordrawable的分离组。android api提供了简单的方法吗?有没有其他方法可以用复杂的动画制作svg的动画?谢谢。
我把这只小猫带到了那里https://hostrider.com/ 我试着复制这个项目来达到教育目的

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题