如何使用Java创建可绘制的动画android矢量

问题描述 投票:0回答:1

我只想使用Java创建可绘制的android矢量并为其添加一些路径,然后为路径添加动画,例如旋转。然后在带有动画的ImageView中显示它。我该如何仅使用Java?

java android android-drawable
1个回答
0
投票

内部res文件夹创建anim文件夹和内部anim文件夹创建rotate_clockwise.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/cycle_interpolator">
    <rotate android:fromDegrees="0"
        android:toDegrees="360"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="5000" />
</set>

rotate_anticlockwise.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/cycle_interpolator">
    <rotate android:fromDegrees="360"
        android:toDegrees="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="5000" />
</set>

现在在Imageview中设置动画,这里R.id.imgvw图像ID enter image description here

ImageView img = (ImageView)findViewById(R.id.imgvw);
Animation aniRotate = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.rotate_clockwise);
img.startAnimation(aniRotate);

您的动画将如下所示。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.