如何将多个 GIF 添加到 Android GridView

How to add multiple GIFs to Android GridView

如何将多个 GIF 添加到 Android GridView?假设我们有一个 4*4 的网格(16 个单元格),每个单元格中显示不同的动画 GIF 图像,每个图像都以自己的方式进行动画处理。因此创建了 16 个不同 videos/animations 的 GIF,同时在 16 个单独的单元格中播放。

您可以使用recyclerview 或gridview。然后在你的适配器中使用 Glide 库

ImageView imageView = (ImageView) findViewById(R.id.imageView);
GlideDrawableImageViewTarget imageViewTarget = new GlideDrawableImageViewTarget(imageView);
Glide.with(context).load(yourGif).into(imageViewTarget);

ImageView imageView = (ImageView) findViewById(R.id.imageView);
Glide.with(context).asGif().load(yourGif).into(imageView);

第一步

在你GridAdapter做一个函数

public void upadteList(List<yourGifList> list){
         this.gifList = list;
         notifyDataSetChanged();
     }

然后在OnBind方法中 打电话
Glide.with(context).asGif().load(gifList).into(imageView);

第二个

在你的 activity 中调用 upadteList() 方法
gridAdapter.updateList(imagesList);

注意:我假设您已经设置了 recyclerView。