I’ve been attempting to get an extremely large canvas working for several days now.
After adding everything to the canvas, the width of the canvas is sometimes 30,000 but if add this code to the ondraw method, scrolling horiztonally becomes really slow.
I then tried to add everything to a bitmap and then draw the bitmap in the onDraw method. Whilst this worked fine for smaller bitmaps, I’m getting out of memory error for the bitmap that is 30,000 wide.
Can anyone suggest a solution please and I’n not sure what to try now.
Thanks
edit I’ve also tried changing the bitmap to Config.RGB_565 but I still get the memory errors.
How many entries do you have in your ArrayList, it appears to be quite large.
From my understanding, you don’t have OoM issue with drawing everything in onDraw(), but that it’s really slow? If that’s the case, the most like reason is that you are calling a large numbers of drawText, this is very slow, basically if you had 10000 Strings to draw, the system will have to measure each and every one of them in order to just determine whether the given String would be visible on your large canvas, and then the actual drawing part is slow as well.
You can test the amount of time taken for drawing all the text and see if this is the case.
If it is indeed the case, then the easiest way is to map each character/number to a bitmap, you can have an artist create the PNG files, or draw each unique character you would need in your onCreate(Bundle) or some other called-once-per-Activity-creation method, put the bitmaps in a String-to-Bitmap HashMap, and instead of calling
you call something like
This will bypass String related drawing overhead completely and should make your onDraw operation quite a bit faster.