首页 > 解决方案 > 如果图像是 HTTP 格式,Imageview 将不会显示带有 piccsso 的图像

问题描述

我正在使用毕加索将图像从 URL 膨胀到 Imageview:


@Override
    public void onBindViewHolder(@NonNull HeroesViewHolder holder, int position) {

        Hero currentHero = heroList.get(position);
        String str = String.join(",", currentHero.abilities);

        holder.heroTitle.setText(currentHero.title);
        holder.heroAbilities.setText(str);
        Picasso.get().load(currentHero.image).resize(500, 500).into(holder.heroesImage);

    }

问题是 HTTP 协议的所有内容都不会显示在模拟器和物理设备上,只会显示 HTTPS 协议。它没有显示它,而是留下了一个黑色空间。

HTTP 协议的图像也是 .png 扩展名,如果这与此有关。

我该如何解决这个问题?

标签: androidhttphttps

解决方案


请尝试以下代码:

Picasso.with(this)  // Activity context
       .load(currentHero.image) // Set URL
       .resize(100,100) // Resize the image
       .placeholder(getResources().getDrawable(R.drawable.ic_defuser)) // Default Image
       .error(getResources().getDrawable(R.drawable.ic_defuser))
       .into(holder.heroesImage); // Imageview

推荐阅读