首页 > 解决方案 > Android Studio中的毕加索库没有从URL加载图像也没有从可绘制资源文件加载

问题描述

我正在使用毕加索图书馆从 URL 加载图像,但它不起作用,我尝试了多个 URL,即使他们在其官方网站http://i.imgur.com/DvpvklR.png上提到

然后我试图从资源目录加载一个可绘制的图像它也没有加载我看到的只是空白屏幕没有错误没有。有人可以提出什么问题吗?

这是一个代码。

活动java文件:


import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;

public class Main2Activity extends AppCompatActivity {

    ImageView iv2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        iv2 = findViewById(R.id.iv2);
        Picasso.get().load(R.drawable.ic_terrain_black_24dp).into(iv2);
    }
}

活动布局:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Main2Activity">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:id="@+id/iv2"
        android:contentDescription="@string/app_name"

        />

</RelativeLayout>

毕加索实现: implementation 'com.squareup.picasso:picasso:2.71828'

顺便说一句,如果此信息有帮助,我的最低 SDK 版本是 16,目标 SDK 是当前默认的 29。

标签: androidpicasso

解决方案


尝试使用占位符和错误图像。

使用毕加索,您可以在Picasso.get()使用.placeholder和之后直接设置它们.error

此外,您应该启用 Picasso 调试。

这三个元素可能会让我们更多地了解为什么您的图像没有加载。


推荐阅读