galaxy s4 and maybe all HD phones? out of memory error inflating layout

后端 未结 3 1441
太阳男子
太阳男子 2020-12-16 04:21

So this app I am working on, works just fine on a really old miserable Android 2.3.3 phone. However when running it on the GS4, the GS4 is throwing out of memory exceptions

3条回答
  •  天涯浪人
    2020-12-16 04:57

    I have discovered the problem. Background images are apparently not handled very efficiently, especially not for a 1920x1080 screen. Therefor you should use a custom xml drawable, a flat color, or a 24-bit jpg. Funny enough I just ran some tests and a 1920x1080 jpeg takes up 95.60 KB while the same image rendered as a png takes up 929.09 KB.

    So I did some testing and found that xml defined drawables with gradients etc. are super fast, I then tried my 1920x1080 jpg and it was super fast, so then I put in a 1920x1080 png and got the error. This is funny to me because the png I has set at the start for HD screens was only 910x540 and I would get the error.

    So lesson here is if you want a image background use a jpg.

提交回复
热议问题