这个章节包含了一些加载和处理位图的常用技术,它们保持你的用户接口(UI)组件可保持响应和避免超出你的程序的内存限制。如果你不小心,位图会很快耗尽你的可用内存预算,由于这个令人畏惧的异常,导致应用程序崩溃:
java.lang.OutofMemoryError:bitmap size exceeds VM budget.为什么在你的应用程序中加载位图是非常复杂的,有许多原因:
-
手机设备普遍具有有限的系统资源。Android设备可以为每个单独的程序分配至少16MB的可用内存。Android Compatibility Definition Document(CDD)文档,3.7.Virtual Machine Compatibility章节给出了各种屏幕大小和分辨率的应用程序最小内存要求。应用程序应该被优化以运行在最小内存限制中。然而,请记住许多设备配置了更高的限制。
-
位图占据了许多资源,尤其是丰富的图片,如照片。例如,在Galaxy Nexus照相机拍照高达2592 * 1936像素(5百万像素)。如果位图设置使用ARGB_8888(Android 2.3之前默认)那么将这个图片加载到内存中将要消耗19MB内存(2592*1936*4byte2),在某些设备上立刻超过每个程序的内存限制。
-
Android应用程序的UI经常需要一次性加载几张位图。例如ListView,GridView和ViewPager控件,它们通常一次性在屏幕上显示多张位图和更多显示的可能不在屏幕中,手指轻轻滑动后准备显示的位图。
课程
有效的下载大的位图
这节课程将引导你如何不超过每个应用的内存限制来编码大的位图。
脱离UI线程处理位图
位图的处理(调整大小,从远程源下载等)不应该发生在主UI线程中。这个课程将引导你使用AsynTask在一后台线程处理位图,并介绍如何处理并发性问题。
缓存位图
这节课程将引导你,在加载多个位图的时候,使用内存和磁盘位图缓存去提高你的UI的响应性和流动性。
在你的UI中显示位图
这节课程将所以的知识融合在一起,向你展示如果利用后台线程和位图缓存,向如ViewPager和GridView控件中加载多个位图。
文档位置:Developers/Training/Advanced Tr
分享到:
相关推荐
Android Cookbook: Problems and Solutions for Android Developers by Ian F. Darwin English | 10 May 2017 | ASIN: B071VLZ9ZK | 838 Pages | AZW3 | 12 MB Jump in and build working Android apps with the ...
Manning RxJava for Android Developers Manning RxJava for Android Developers
Kotlin for android developers 中文学习文档 https://leanpub.com/kotlin-for-android-developers 英文版 - Github: https://github.com/wangjiegulu/kotlin-for-android-developers-zh
Kotlin for android developers中文版翻译 Kotlin for android developers中文版翻译
本书介绍Scala基本语法、构造。以及如何将您已经知道的复制java语法转换为Scala,了解Scala除了javabecome之外还提供了哪些功能编程概念和惯用技巧和建议,这些技巧和建议在将现有java项目转换为Scala时非常有用
kotlin for android developers 中文版, kotlin for android developers 中文版
Linux for Developers: Jumpstart Your Linux Programming Skills (Developer's Library) by William "Bo" Rothwell English | 17 Apr. 2017 | ASIN: B06ZY85CPJ | 224 Pages | AZW3 | 5.37 MB Linux for ...
《Kotlin for android developers中文版翻译》
Wiley - Java Programming for Android Developers - For Dummies 2nd - 2017
CalendarProvider是用于用户的日历事务的仓库。...通常地,读或者写日历数据,一个应用程序的清单文件必须包含相应的权限,在UserPermission中被描述。为了更简单的执行共同的操作,CalendarProvider支持一系列的
Kotlin-for-Android-Developers:该书的配套应用
kotlin-for-android-developers-zh 中文版本,请支持正版。 https://leanpub.com/kotlin-for-android-developers
Kotlin for android developers(非扫描中文)下载后解压即可,更多请关注我的博客:xiayye5
Kotlin for Android Developers 中文版 ---------------------------------------------------- 本 ePub 基于开源文档,目录书签齐全。 版权归原作者,翻译版权归译者。 ------------------------------------------...
Kotlin for Android Developers - Learn Kotlin the easy way.pdf
kotlin-for-android-developers; kotlin-for-android-developers; kotlin-for-android-developers;
Java Programming for Android Developers For Dummies(2nd) 英文mobi 第2版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
Master the fundamentals of Scala and understand its emphasis on functional programming that sets it apart from ...Java developers looking to transition to Scala. No prior experience necessary in Scala.