我正在做一个基本的Android Studio项目,用于使用Picasso和Kotlin将URL加载到ImageView中。我已经完成了毕加索官方网页的每一步,但是当我运行我的应用程序时,模拟器显示一个空视图。
在我的Gradle中,我添加了Picasso的实现:
implementation 'com.squareup.picasso:picasso:2.71828'
清单标签中的Internet权限也是:
<uses-permission android:name="android.permission.INTERNET"/>
在MainActivity
毕加索的基本用法:
Picasso.get().load("http://paproject.online/hp.jpg").into(imageTest)
imageTest
是与Imageview
和layout_height = 200dp
的layout_weight = 200dp
的id。
也许你的照片尺寸太大,所以在ImageView
中的XML
标签编辑layout_width
和layout_height
到Const尺寸像100dp。
如果你可以用Glide改变毕加索。也许可以帮到你
您的图像比ImageView更大(1024x768),但当然这不应该是您变得空白的原因。尝试如下,其中还包括错误情况的本地图像资源nopic。似乎你有正确的包含
// Lazy load the image with Picasso
get()
.load(yourURL)
.placeholder(R.drawable.nopic)
.error(R.drawable.nopic)
.into(img);
您可以在将图像包含到imageView之前调整图像大小
Picasso
.with(context)
.load("http://paproject.online/hp.jpg")
.resize(200, 200) // resizes the image to these dimensions.
.into(imageViewResize);
或者您可以使用任何裁剪技术,如.CenterCrop()。你可以阅读更多关于这个https://futurestud.io/tutorials/picasso-image-resizing-scaling-and-fit的信息
好的,问题已经解决了。似乎在Android 9.0中加载图像时出现问题。所以解决方案是在这个链接:Picasso image loading issue with Android 9.0 Pie。感谢大家的回复。