要使用 Glide 加载 animation-list 到 ImageView,需要进行以下步骤:

  1. 在 Android 项目的 build.gradle 文件中添加 Glide 依赖:
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
  1. 创建一个 animation-list 资源文件,例如my_animation.xml,定义一个动画列表,其中每个帧都是一个 Drawable 资源:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false">
    <item android:drawable="@drawable/frame1" android:duration="100" />
    <item android:drawable="@drawable/frame2" android:duration="100" />
    <item android:drawable="@drawable/frame3" android:duration="100" />
    ...
</animation-list>
  1. 在代码中使用 Glide 加载 animation-list 到 ImageView:
ImageView imageView = findViewById(R.id.image_view);
Glide.with(this)
    .load(R.drawable.my_animation)
    .into(imageView);

确保将R.drawable.my_animation替换为您自己的 animation-list 资源。

这样,Glide 将加载 animation-list 并将其设置为 ImageView 的背景动画。

Android Glide 加载 Animation-List 到 ImageView 教程

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

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