android - large images cause app crash

让人想犯罪 __ 提交于 2020-01-13 06:40:10

问题


I'm working on a tablet app. I tried to set high-resolution (2223x3553) images as background using Layout.setBackgroundResource(ResId). The app crashed while testing on Nexus 7, I won't paste the stack traces since there were like 8 or 9 exceptions with about 300 red lines in the LogCat and it took me a while to figure out the reason. I got it after I noticed the OutOfMemoryException, using 1280x800 images the app runs fine but some quality loss has occurred since those images are designed to be high-res.

The question: how to handle high-resolution images in Android to prevent crashes like that? All images are local and stored in the drawable folder


回答1:


You have to use same library that I have used in such a Use Case ,

This project will help you in yours also. Because you need to compress the images while displaying them and also use the capability of lazy loading if you need eventually.




回答2:


Image sizes are limited in android development. You can not use images which are bigger than the prescribed ones. There is a guideline about how to choose images for your application. This is the link to the guidelines.



来源:https://stackoverflow.com/questions/14998687/android-large-images-cause-app-crash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!