在做一款聊天软件,其中聊天界面需要发送表情,而表情都是动图,在安卓中想要显示动图,就要借助第三方框架,我选的是pl.droidsonroids.gif.GifImageView。
使用方法如下:你在github上下载了android-gif-drawable.aar后,解压后,将jni文件下的所有文件夹以及classes.jar拷贝到你安卓项目的libs文件下,然后将你项目代码中的imageview换成第三方的,效果如下:
java类中代码:
GifImageView gifImageView=(GifImageView) view.findViewById(R.id.gifImageview);
GifDrawable gifDrawable==new GifDrawable(context.getAssets(), faceFileName[position]);
//gifImageView.setBackgroundDrawable(gifDrawable);//虽然过时,但是支持老版本
gifImageView.setBackground(gifDrawable);
项目地址:https://github.com/koral--/android-gif-drawable
注意:这里有一个坑,就是android-gif-drawable.aar与安卓sdk版本的兼容问题,不是下载最新的就是最好的,一定要版本对应,我刚开始做的时候下载的是最新版,而我的项目的sdk为android4.2.2,即API17.后来下了其他版本的,一下就好了,所以谨记版本问题
版本不对,报错内容如下:
AndroidRuntimeException:Binary xml file line error inflate class pl.droidsonroids.gif.GifImageView
Caused by: java.lang.NoClassDefFoundError: .R$styleable
最后想达到的效果如下: