android - large images cause app crash

2020-07-27 05:59发布

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

2条回答
淡お忘
2楼-- · 2020-07-27 06:30

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.

查看更多
该账号已被封号
3楼-- · 2020-07-27 06:31

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.

查看更多
登录 后发表回答