为了账号安全,请及时绑定邮箱和手机立即绑定

如何从远程源(url)获取图像并在图像视图中显示它?

如何从远程源(url)获取图像并在图像视图中显示它?

郎朗坤 2022-09-28 15:32:01
我正在构建一个Android Things“信息亭”风格的应用程序,我希望图像像壁纸一样显示在背景中。我使用Unsplash源来获取随机图像,但源URL(https://source.unsplash.com/1080x1920/?long-exposure)总是重定向到图像URL,所以我不能使用这个:InputStream is = (InputStream) new URL("https://source.unsplash.com/1080x1920/?long-exposure").getContent();Drawable d = Drawable.createFromStream(is, "");niceWallpaper.setImageDrawable(d);有没有办法做到这一点?
查看完整描述

2 回答

?
浮云间

TA贡献1829条经验 获得超4个赞

使用可以解决您的问题。Picasso

String yourUrl = "https://source.unsplash.com/1080x1920/?long-exposure";
Picasso.with(MyApplication.getAppContext()).load(yourUrl).placeholder(defaultImage).memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE).into(YourImageView);


查看完整回答
反对 回复 2022-09-28
?
潇潇雨雨

TA贡献1833条经验 获得超4个赞

使用毕加索

Picasso.get().load("https://source.unsplash.com/1080x1920/?long-exposure")
                            .into(imageView);


查看完整回答
反对 回复 2022-09-28
  • 2 回答
  • 0 关注
  • 139 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号