Caching Bitmaps(官方文档)

Displaying Bitmaps Efficiently系列

  1. Loading Large Bitmaps Efficiently
  2. Processing Bitmaps Off the UI Thread
  3. Caching Bitmaps
  4. Managing Bitmap Memory
  5. Displaying Bitmaps in Your UI

Caching Bitmaps(缓存)

Use a Memory Cache

The LruCache class is particularly well suited to the task of caching bitmaps, keeping recently referenced objects in a strong referenced LinkedHashMap(强引用) and evicting the least recently used member before the cache exceeds its designated size.

  1. 如何选择一个合适的LruCache大小

    • How memory intensive is the rest of your activity and/or application?
    • How many images will be on-screen at once? How many need to be available ready to come on-screen?
    • What is the screen size and density of the device? An extra high density screen (xhdpi) device like Galaxy Nexus will need a larger cache to hold the same number of images in memory compared to a device like Nexus S (hdpi).
    • What dimensions and configuration are the bitmaps and therefore how much memory will each take up?
    • How frequently will the images be accessed? Will some be accessed more frequently than others? If so, perhaps you may want to keep certain items always in memory or even have multiple LruCache objects for different groups of bitmaps.
    • Can you balance quality against quantity? Sometimes it can be more useful to store a larger number of lower quality bitmaps, potentially loading a higher quality version in another background task.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值