简体   繁体   English

将图像从url加载到Recyclerview

[英]Load image from url to Recyclerview

I have an app that loads content from a database as well as images from the internet. 我有一个应用程序,可以从数据库加载内容以及来自互联网的图像。 I am using a RecyclerView along with CardView to display my content in a list form. 我使用RecyclerViewCardView以列表形式显示我的内容。

Each row has an image on the left side and text on the right. 每行左侧有一个图像,右侧有文本。 The problem is that the text loads fast but the image takes time to load, so I want the image to continue loading in the background and then load into the ImageView object once loading is complete. 问题是文本加载速度很快但图像需要时间加载,所以我希望图像继续在后台加载,然后在加载完成后加载到ImageView对象中。 I have no idea how to tackle this. 我不知道如何解决这个问题。

I use Picasso for this situation, but u can also use Glide and many more libraries. 我在这种情况下使用Picasso ,但你也可以使用Glide和更多的库。 The documentation is pretty simple. 文档非常简单。

Try Picasso: http://square.github.io/picasso/ 试试毕加索: http//square.github.io/picasso/

It's a one liner in onBindViewholder(): Picasso.with(context).load(url).into(viewHolder.imageView); 它是onBindViewholder()中的一个衬垫:Picasso.with(context).load(url).into(viewHolder.imageView);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM