koraxis
koraxis

Reputation: 811

Slow App with Background image

I am making a small game for android. It is working smoothly when its working on a white background but when i want to put a background image, its becoming slower and slower. First i tried to add it as a layout background image but it was very slow, the animations were happening frame by frame. And then i decided to draw the background image as a Bitmap on canvas, the result was a little faster than the previous one but still its nothing comparing to the white background.

I tried to scale the image many times, i did it with higher resolution, lower resolution, but the result didnt change, its still slower.

So i wanted to ask, is there a way to add a background image to an android app without losing the smoothness and speed of the application?

Thanks

P.S: I am trying my application on Sony Tablet S

Upvotes: 31

Views: 15640

Answers (7)

Ravikumar Mohan
Ravikumar Mohan

Reputation: 11

Background image Resolution to maintain smoothness

DPI Size in Pixels
xxxhdpi 1280x1920
xxhdpi 960x1600
xhdpi 640x960
hdpi 480x800
mdpi 320x480
ldpi 240x320

You need to use background pictures matching the resolution as above to avoid lagging or being slow down.!

If you use high resolution images which exceeds the above restrictions would actually cause this issue and it's advisable to use only png

Upvotes: 0

Atul Jha
Atul Jha

Reputation: 1

Iam also facing the same problem, I have a very simple app when Iam running it on a white background it is working completely fine. But when Iam adding a background Image it is Lagging, but after some tweaks I have figured out how to smoothly run the app with a background Image. You just need to resize your Background Image, and also lower the quality of Image, this is because the size of Image is directly proportional to your apps performance. So the only solution is to resize it and decrease the quality of Image. I hope my answer will be helpful to you.

Upvotes: -1

BeatingBytes
BeatingBytes

Reputation: 351

enter image description here

I was in the same position as you. I have a very simple app and it has lags when i add some background. Try this app 9-patch-resizer - Transform the image dimensions for all screens

And then comes this tool, that takes a xhdpi PNG file, or 9.png file, and generates ldpi, mdpi and hdpi png files automatically.

When it transoforms the image , move the each file to its own project folder (resources/mipmap-hdpi ,mipmap-xhdpi ...etc)

Upvotes: 1

Mrigesh Raj
Mrigesh Raj

Reputation: 51

The main reason you're noticing the lag is because the image needs to because you need to copy your background image to all the drawable folders (drawable-hdpi,drawable-xhdpi...etc.) . I use the Android Studio plugin named Android Drawable Importer for automating. Works like a charm.

Upvotes: 4

SajithK
SajithK

Reputation: 842

Recently i had the same issue and no answer helped me.But after playing with codes so many hours i found an amazing solution.What you have to do is copy your background image to all the drawable folders (drawable-hdpi,drawable-xhdpi...etc.) and thats it. And also my background image is png with 590kb file size. Be careful with image size because higher the size is slower the app. Hope this help to someone. :-)

Upvotes: 14

Alp
Alp

Reputation: 1893

its pretty late but if someone else have the same problem ; on the draw it may try to resize again, you can use no-dpi (drawable-nodpi / drawable-sw600dp-nodpi) folder to skip resizing which requires so much cpu and time.

also something else may cause this , which i assume you forget to recycle old your bitmaps.

Upvotes: 47

mmoghrabi
mmoghrabi

Reputation: 1291

For excellent performance use tiled background you can find nice explanation for it here

Upvotes: 1

Related Questions