效果图:
SketchImageView https://github.com/panpf/sketch
引用:
implementation 'me.panpf:sketch:2.7.0'
implementation 'me.panpf:sketch-gif:2.7.0'
布局
<?xml version="1.0" encoding="utf-8"?>
<me.panpf.sketch.SketchImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@mipmap/ic_launcher"
android:id="@+id/ivImg"
android:adjustViewBounds="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</me.panpf.sketch.SketchImageView>
加载图片
val url = "https://yd-imgs.380star.com/upload/uploadfile/2020/4/23/158763676174928364815980349689.jpg"
if (url.endsWith("gif")){
ivImg?.let {
it.options?.isDecodeGifImage = true
Sketch.with(context).display(itemBean, it)
.decodeGifImage()
.commit();
}
}else{
ivImg?.let {
it.displayImage(itemBean)
}
}
class ImgViewHolder(view: View):RecyclerView.ViewHolder(view){
var ivImg: SketchImageView? = null
init {
ivImg = view.findViewById(R.id.ivImg)
}
}