android - Android Studio中的毕加索库没有从URL加载图像也没有从可绘制资源文件加载
问题描述
我正在使用毕加索图书馆从 URL 加载图像,但它不起作用,我尝试了多个 URL,即使他们在其官方网站http://i.imgur.com/DvpvklR.png上提到
然后我试图从资源目录加载一个可绘制的图像它也没有加载我看到的只是空白屏幕没有错误没有。有人可以提出什么问题吗?
- 我已获得 Internet 许可。
- 我使用了来自 Github 的最新版本的毕加索。
这是一个代码。
活动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。
解决方案
尝试使用占位符和错误图像。
使用毕加索,您可以在Picasso.get()
使用.placeholder
和之后直接设置它们.error
此外,您应该启用 Picasso 调试。
这三个元素可能会让我们更多地了解为什么您的图像没有加载。
推荐阅读
- python - Python数据汇总和结构
- javascript - 在表格中使用 ng-repeat 未触发 ng-click 事件
- python - 如何使用 python 在 O(1) 时间内找到有多少整数落入范围 [a...b]?
- winforms - windows窗体面板上的随机坐标
- javascript - React Native - flex 内的短文本:1 个视图
- java - 不可转换的类型:无法将 android.view.View 转换为 androidx.webkit.WebViewCompat 我如何使用 androidx?
- ios - PushKit 委托方法 didReceiveIncomingPushWithPayload 在 iOS 13 及更高版本的设备中未在后台调用和终止状态
- powerapps - powerapps 模型驱动 vs 画布
- python - 函数过滤器必须通过删除所有项目 a[i] 来修改列表 a,使得 b[i] 为 False
- python - 创建聊天机器人时出现 sqlalchemy.exc.ArgumentError