在 Android 中调整图像大小以便在列表视图中使用
我有一堆“大”400x400 图像,是从网络上的源中提取的,我需要在 Android 上的 ListView 中显示为 100x100 缩略图。如果我只是在 xml 中设置 imageview 元素的尺寸,很明显它只是将图像压缩到 100x100,原因有两个:
1)图像看起来没有重新采样 2)当列表中的图像超过 10 个时,滚动会变得慢得难以忍受,
我并不担心#1,但滚动需要保持平滑。所以我想知道,我应该如何调整这些图像的大小/重新采样并缓存它们?我已经进行了一些谷歌搜索,但我只是找不到在这种情况下最佳实践的良好资源。
提前致谢!
I have a bunch of "large" 400x400 images that I am pulling from a source on the web and I need to display as 100x100 thumbnails in a ListView on Android. If I simply set the dimensions on the imageview element in xml it is very clear it is only scrunching the images down to 100x100 for 2 reasons:
1) The images don't look resampled
2) When given more than lets say 10 of these images in the list the scrolling becomes unbearably slow
I am not AS worried about #1 but the scrolling needs to stay smooth. So I am wondering, how should I go about resizing/resampling these images and caching them? I've done some googling but I just can't find a good resource for what would be a best practice in this situation.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看一下 BitmapFactory 和 选项 类。
Options
有一个inSampleSize
值,您可以将其设置为在读入图像时缩小图像。您可以尝试类似的操作Take a look at BitmapFactory and the Options class.
Options
has aninSampleSize
value that you can set to scale down an image when you read it in. You could try something like只需设置
android:scaleType="fitCenter"
,您的图像就会缩小到您想要的尺寸。Just set
android:scaleType="fitCenter"
and your image will be scaled down to your desired size.