是的,使用 Property Animation 可以实现给 ImageView 循环播放一系列的 drawable。以下是一种可能的实现方法:

  1. 首先,将你的一系列 drawable 资源文件放在 res/drawable 目录下。

  2. 在你的布局文件中,添加一个 ImageView 组件:

<ImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/your_starting_drawable"
/>
  1. 在你的 Java 代码中,使用 Property Animation 来实现循环播放 drawable 资源。
ImageView imageView = findViewById(R.id.imageView);

// 加载需要循环播放的 drawable 资源
int[] drawableIds = {R.drawable.drawable1, R.drawable.drawable2, R.drawable.drawable3};
Drawable[] drawables = new Drawable[drawableIds.length];
for (int i = 0; i < drawableIds.length; i++) {
    drawables[i] = getResources().getDrawable(drawableIds[i]);
}

// 创建 Property Animation 对象
ObjectAnimator animator = ObjectAnimator.ofInt(imageView, 'imageResource', drawableIds);
animator.setDuration(1000); // 设置动画时长
animator.setRepeatCount(ValueAnimator.INFINITE); // 设置重复次数为无限
animator.setRepeatMode(ValueAnimator.RESTART); // 设置重复模式为重新开始

// 开始动画
animator.start();

这样,ImageView 将会循环播放 drawable1、drawable2 和 drawable3 这三个资源文件。你可以根据自己的需求来修改数组 drawableIds 中的 drawable 资源文件。

Android ImageView 循环播放 Drawable 动画实现

原文地址: https://www.cveoy.top/t/topic/qurf 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录