Learn Android Tutorial 1.28- Introduction to the SurfaceView

mybringback · 109K views · 2011 · 7:31

Open on YouTube

Software (other)Game programming & enginestutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it when explaining how to use SurfaceView to draw on Android from a background thread, such as for moving bitmaps or simple game graphics.

Recommended by 5 people across 4 different months, 2012 to 2013.

What it is

A short Android tutorial from the mybringback channel (episode 1.28) that introduces SurfaceView. It shows how to set up a separate thread for graphics rather than drawing on the main UI thread, as a basic setup before doing actual drawing.

What people said

Recommends Alex Orlov · 2012-06 · Stack Overflow · on “How to draw on Canvas in another thread?”

You can only draw in the main UI thread. You should use SurfaceView, since it was made specifically to support drawing from secondary threads. One of the purposes of this class is to provide a surface in which a secondary thread can render into the screen. If you are going to use it this way, you need to be aware of some threading semantics. source [LINK] See also this video: Learn Android Tutorial 1.28- Introduction to the SurfaceView [this video]

Recommends Samuel · 2012-10 · Stack Overflow · on “how to edit surfaceView in layout?”

You can't draw images in a SurfaceView from a layout file. You need to get a reference of the SurfaceView from your activity like so: SurfaceView sv = (SurfaceView) findViewById(R.id.hero3); Additionally, you can't modify the SurfaceView specific properties of the SurfaceView from layouts. If you check out the documentation [LINK] , the only XML attributes that the SurfaceView has are the ones provided by View. You can modify the SurfaceView specific properties from code using the reference above. For example: sv.setZOrderOnTop(true); Drawing onto a SurfaceView is a little more complex, and you should weigh the benefits of using the SurfaceView instead of a regular View [LINK] . if you decid

Recommends Ashwin · 2012-11 · Stack Overflow · on “Switching from surfaceview to main activity class”

You should not do this : MainActivity activity = new MainActivity(); Instead try this : MainActivity activity = MainActivity.this; As far as posting a new set of bitmaps is concerned, I have done it like this in my app : public class OurView extends SurfaceView implements Runnable { Thread t=null; SurfaceHolder holder; boolean ok; public OurView(Context context) { super(context); holder=getHolder(); } public void run() { //draw the bitmaps } public void pause() { ok=false; Log.v("pause()", "ok=false"); while(true) { try{ t.join(); } catch(InterruptedException e) { Log.v("pause()",e.toString()); } break; } t=null; } public void resume() { ok=true; if(t==null) { t=new Thread(this); t.start();

Recommends Kirill Kulakov · 2012-11 · Stack Overflow · on “How to move ball on android”

You could find how to do so over here, however as @vizier I'd recommend you to use a game engine which will handle all that for you [this video]

Recommends Ahmed Ekri · 2013-02 · Stack Overflow · on “Android Moving Bitmap in canvas”

You need to use the SurfaceView widget that is available in the XML But if you want the image to be move-able around all the screen you could use SurfaceView Check this Youtube video, It's very informative (watch all the SurfaceView playlist to benefit) [this video]