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

我正在构建一个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);

有没有办法做到这一点?


郎朗坤
浏览 140回答 2
2回答

浮云间

使用可以解决您的问题。PicassoString 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);

潇潇雨雨

使用毕加索。Picasso.get().load("https://source.unsplash.com/1080x1920/?long-exposure")                             .into(imageView);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java