如何在列表视图中按需显示图像?
我正在构建一个 android 应用程序,它将使用来自互联网的 json 文件。此 json 文件包含来自特定网站的新闻列表。每个 json 对象都包含新闻缩略图和原始图像的标题、摘要、描述以及 Web 链接等信息。
我将在列表视图中显示三个信息:新闻缩略图、标题和摘要。我的问题就在这里。如果无法显示,我不想从互联网加载所有缩略图。我想说的是,如果用户不向下滚动图像,为什么要下载第 30 条新闻的缩略图呢?因此,我最初只会下载屏幕上显示的新闻的缩略图,当用户向下滚动以查看更多新闻时,一旦列表项出现在屏幕上,我想下载图像然后显示。
有办法实现这一点吗?是否可以查明列表项是否在屏幕上?我一直在互联网上寻找解决方案,但我已经没有想法了。
谢谢 时间
I am building a android aplication which will be consuming a json file from the internet. This json file contains a list of news from a particular website. Each json object contains information such like title, summary, descripition and web links for the news thumbnail and the original image.
I will be displaying in a listview three information: the news thumbnail, the title and the summary. Here resides my problem. I dont want to load all thumbnails from the internet if they wont be displayed. What I am trying to say is that why download a thumbnail from the 30th news if the user wont scroll down the image. So, i will, initially only download the thumnails from those news that are being displayed in the screen and when the user scrolls down to see more news, as soon as the list item appers to the screen i want to download the image and then display.
Is there a way to achieve this? Is it possible to find out if the list item is on the screen? I have been searching all over the internet for a solution for this but i am running out of ideas.
Thanks
T
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您本质上想要延迟加载图像. 这只会加载当前显示的图像,当您滚动列表视图时,它将去获取当前显示的图像。
You essentially want to lazy load your images. This will only load images that are currently being shown and as you scroll through the list view it will go and fetch those currently shown images.