Android Studio 中的 Picasso 库无法从 URL 加载图像,也无法从可绘制资源文件加载
Picasso library in Android Studio not loading image from URL also not loading from drawable resource file
我正在使用 Picasso Library 从 URL 加载图像,但它不起作用,我尝试了多个 URLs 即使他们在他们的官方网站上提到 http://i.imgur.com/DvpvklR.png
然后我尝试从资源目录加载可绘制图像,它也没有加载,我看到的只是空白屏幕,没有错误。有人可以告诉我哪里出了问题吗?
- 我已获得互联网许可。
- 我使用了 Github 的最新版 Picasso。
这是一个代码。
Activity 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);
}
}
Activity布局:
<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。
尝试使用占位符和错误图片。
使用 Picasso,您可以在 Picasso.get()
之后直接设置 .placeholder
和 .error
您还应该启用 Picasso 调试。
这三个要素可能会给我们更多信息,以了解您的图片未加载的原因。
我正在使用 Picasso Library 从 URL 加载图像,但它不起作用,我尝试了多个 URLs 即使他们在他们的官方网站上提到 http://i.imgur.com/DvpvklR.png
然后我尝试从资源目录加载可绘制图像,它也没有加载,我看到的只是空白屏幕,没有错误。有人可以告诉我哪里出了问题吗?
- 我已获得互联网许可。
- 我使用了 Github 的最新版 Picasso。
这是一个代码。
Activity 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);
}
}
Activity布局:
<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。
尝试使用占位符和错误图片。
使用 Picasso,您可以在 Picasso.get()
之后直接设置 .placeholder
和 .error
您还应该启用 Picasso 调试。
这三个要素可能会给我们更多信息,以了解您的图片未加载的原因。