Created
April 5, 2016 08:16
-
-
Save jingwings/6c4015da25c32a33e4b130944b3a78a2 to your computer and use it in GitHub Desktop.
SurfaceViewTempalte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SurfaceViewTempalte extends SurfaceView implements SurfaceHolder.Callback, Runnable { | |
private SurfaceHolder mHolder; | |
private Canvas mCanvas; | |
private Thread t; | |
private boolean isRunning; | |
public SurfaceViewTempalte(Context context) { | |
super(context, null); | |
} | |
public SurfaceViewTempalte(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
mHolder = getHolder(); | |
mHolder.addCallback(this); | |
//可获得焦点 | |
setFocusable(true); | |
setFocusableInTouchMode(true); | |
//设置常量 | |
setKeepScreenOn(true); | |
} | |
@Override | |
public void surfaceCreated(SurfaceHolder holder) { | |
isRunning = true; | |
t = new Thread(this); | |
t.start(); | |
} | |
@Override | |
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { | |
} | |
@Override | |
public void surfaceDestroyed(SurfaceHolder holder) { | |
isRunning = false; | |
} | |
@Override | |
public void run() { | |
while (isRunning) { | |
draw(); | |
} | |
} | |
private void draw() { | |
try { | |
mCanvas = mHolder.lockCanvas(); | |
if (mCanvas != null) { | |
} | |
} catch (Exception e) { | |
} finally { | |
if (mCanvas != null) { | |
mHolder.unlockCanvasAndPost(mCanvas); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment