SurfaceView sample code

saranya krishnan picture saranya krishnan · Mar 8, 2011 · Viewed 14k times · Source

I need a sample tutorial for the android SurfaceView, or sample code using it that can be shared. The API demos are difficult for me to understand. Does anyone have alternatives?

Answer

JohnnyLambada picture JohnnyLambada · Apr 17, 2012

This commit of my WorldMap demo app shows you the changes necessary to convert from an android.view.View to an android.view.SurfaceView with an android.view.SurfaceHolder.Callback.

It cheats a bit by using the View's onDraw() from within the SurfaceView's DrawThread and by calling the View's onSizeChanged() from within the SurfaceView's surfaceChanged. It just makes the diff smaller and easier to understand.