如何在Recycler视图中从Url加载图像 [英] How to load image from Url in Recycler view

查看:126
本文介绍了如何在Recycler视图中从Url加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是android新手,我想知道如何在Recycler视图中加载 URL 中的图像,并轻松定义<$ c $的用法c>位图及从 URL 加载图像时的功能。我不想使用任何第三方库。请为此提供解决方案。

I'm new to android, I want to know how to load an image from URL in Recycler view and easy definition of what is the use of Bitmap and their functions while loading the image from URL. I don't want to use any third party library. Kindly provide the solution for this.

推荐答案

您的问题似乎有点不清楚要么您要求使用URL或任何内容阅读图像其他。如果是这样,您可以读取图像并将其设置为 ImageView ,就像这样

Your question seems a bit unclear Either you are asking for reading the image with URL or anything else. If so you can Read Image and set It to your ImageView like this way

InputStream in = (InputStream) new URL(imageUrl).getContent(); //Reads whatever content found with the given URL Asynchronously And returns.
                Bitmap bitmap = BitmapFactory.decodeStream(in); //Decodes the stream returned from getContent and converts It into a Bitmap Format
                yourImageView.setBitmap(bitmap); //Sets the Bitmap to ImageView
                in.close(); //Closes the InputStream

其中 imageUrl 是一个完整的URL,指向您的图像,如 something.com/image1.jpg

Where imageUrl is a complete URL which points to your Image like something.com/image1.jpg

这篇关于如何在Recycler视图中从Url加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆