美文网首页UI
android recycleview+image加载图片(长图

android recycleview+image加载图片(长图

作者: hao_developer | 来源:发表于2020-12-23 17:02 被阅读0次

效果图:

image.png
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)
   }
 }

相关文章

网友评论

    本文标题:android recycleview+image加载图片(长图

    本文链接:https://www.haomeiwen.com/subject/xykunktx.html