Imgur图片无法通过下滑库加载

时间:2019-05-19 16:41:31

标签: android image url android-glide

我正在尝试使用glide库将imgur中的图像加载到一个简单的图像视图中,但这会抛出此错误:

2019-05-19 09:34:15.999 5714-5714/com.bottlerocket W/Glide: Load failed for https://imgur.com/a/xYQOEhQ with size [1028x525]
    class com.bumptech.glide.load.engine.GlideException: Failed to load resource
    There were 2 causes:
    java.io.IOException(java.lang.RuntimeException: setDataSource failed: status = 0x80000000)
    java.io.IOException(java.lang.RuntimeException: setDataSource failed: status = 0x80000000)
     call GlideException#logRootCauses(String) for more detail

我已经尝试从滑行.Override()并使用.AsBitmap()、. AsGif()覆盖图像的大小。我也尝试过使用picasso库加载这些图像,并且仅加载一组图像,该图像的URL以.gif而不是上面的结尾。

这是我的适配器:

package com.bottlerocket.gallery
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.cardview.widget.CardView
import androidx.recyclerview.widget.RecyclerView
import com.bottlerocket.R
import com.bottlerocket.entities.Image
import com.bumptech.glide.Glide

class GalleryAdapter (
        context : Context,
        private val onImageSelected: (Image) -> Unit
) : RecyclerView.Adapter<GalleryAdapter.ViewHolder>() {

    private val imageList: MutableList<Image> = mutableListOf()
    var adapterContext = context


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.image_list_item_layout, parent, false)
        return ViewHolder(view)
    }

    override fun getItemCount(): Int {
        return imageList.count()
    }

    fun addImages(images: List<Image>) {
        imageList.addAll(images)
        notifyDataSetChanged()
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val image = imageList.get(position)
        holder.imageName.text = image.imageTitle

        Glide.with(adapterContext)
            .load(image.imageLink)
            .placeholder(R.drawable.placeholder)
            .into(holder.imageContent)

        holder.imageContainer.setOnClickListener {
            onImageSelected.invoke(image)
        }
    }

    class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        var imageContainer = view.findViewById<CardView>(R.id.image_container)
        var imageName = view.findViewById<TextView>(R.id.image_title)
        var imageContent = view.findViewById<ImageView>(R.id.image_content)
    }
}

1 个答案:

答案 0 :(得分:0)

  

https://imgur.com/a/xYQOEhQ是一个网页。

要加载图像/ gif文件,您需要一个不包含HTML或其他网页的纯URL。例如:

Glide.with(adapterContext)
   .load("https://i.imgur.com/i4ZEaLM.gif")
   .placeholder(R.drawable.placeholder)
   .into(holder.imageContent)