android view or surfaceView, which should i use?

jfisk picture jfisk · Jul 30, 2010 · Viewed 7.4k times · Source

Ive been trying to make a scrollable/zoomable app and everything has gone great except for drawing bitmaps. It is a very large image (6656 by 4096) that i have split into tiles. There is a rectangle array that the bitmaps are drawn to, and it detects what rectangle is in the top left corner so it can draw the bitmaps that will cover the user's viewable screen. My problem is this all lags when the app has to load the bitmaps into memory; Once they are loaded it isnt an issue. I started with 512 by 512 tiles, then went down to 128 by 128. although it helped, there still is some noticeable lag. I have been looking into surfaceView and wanted your opinions if i should stick with View, or use surfaceView to solve my lag.

Answer

monoceres picture monoceres · Jul 30, 2010

If you derive your own SurfaceView you have several advantages.

Mainly because you can have all drawing logic in a seperate thread. This means that the ui won't wait for you (I'm assuming the lag is because the ui-thread is being blocked?).

SurfaceView's are also faster in nature.

I also find this overview on developer.android.com to be a good reference to choose drawing method.