A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

Android加载GIF图片的两种方式
方式一:使用第三开源框架直接在布局文件中加载gif
1.在工程的build.gradle中添加如下
buildscript {
        repositories {
            mavenCentral()
        }
    }
    allprojects {
        repositories {
            mavenCentral()
        }
    }
1
2
3
4
5
6
7
8
9
10
2.在app的build.gradle中添加依赖
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.1'

3.布局文件中就可以直接写你需要加载的gif图片即可
<pl.droidsonroids.gif.GifImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/gif2" />
1
2
3
4
方式二:使用Glide加载gif
这种方式就比较简单了,直接看代码↓

1.添加Glide图片加载框架依赖
implementation 'com.github.bumptech.glide:glide:4.7.1'

2.布局文件中写一个普通的Imageview
<ImageView
        android:id="@+id/ivGif"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
1
2
3
4
3.代码中直接加载本地的gif图片到Imageview上即可
RequestOptions options = new RequestOptions()
                .diskCacheStrategy(DiskCacheStrategy.RESOURCE);
Glide.with(mContext).load(R.drawable.gif1).apply(options).into(ivGif);
1
2
3
以上就是加载gif图片的两种方式
---------------------
作者:IT大飞说
来源:CSDN
原文:https://blog.csdn.net/xinpengfei521/article/details/72809013
版权声明:本文为博主原创文章,转载请附上博文链接!

1 个回复

倒序浏览
奈斯
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马