Surface View vs View — the differences

In this article, I’ll share with you what is SurfaceView and the differences with normal View in term of implementing it.

Background

We knew we could create animated drawing on a view as per in my tutorial below

However, when we use onDraw to perform all the animation calculation, we are doing it on the UI thread. If we also need to handle user interaction, this will be a challenge, as the animation calculation has taken up all the processing time, this will make the user interaction unresponsive.

I’m providing a simple illustration below, where I put my animated view in a scroll view, and I explicitly sleep 0.5s for each animation (simulating slow processing).

canvas.drawRect(...)
Thread.sleep(500)
moveRectRight()

When I scroll the view up and down, look at how slow the view response to it.

--

--