@vxg
Модератор
3217 / 2020 / 230
Регистрация: 13.01.2012
Сообщений: 7,829
|
27.09.2015, 14:22
|
|

Сообщение от tronuo
Вот.
сделайте
Java | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
| public class MainSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
private Context ctx;
private MainThread mainThread = null;
public MainSurfaceView(Context context) {
super(context);
getHolder().addCallback(this);
ctx = context;
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
mainThread = new MainThread(getHolder(), ctx);
mainThread.start();
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
mainThread.terminate();
while (true) {
try {
mainThread.join();
break;
} catch (InterruptedException e) {
}
}
}
}
class MainThread extends Thread {
private SurfaceHolder surfaceHolder;
private Context ctx;
private boolean terminated;
private Canvas canvas;
public MainThread(SurfaceHolder surfaceHolder, Context ctx){
this.surfaceHolder = surfaceHolder;
this.ctx = ctx;
terminated = false;
}
public void terminate() {
terminated = true;
}
private void draw() {
...
}
@Override
public void run() {
while (!terminated) {
canvas = null;
try {
canvas = surfaceHolder.lockCanvas(null);
if (canvas != null) {
synchronized (surfaceHolder) {
draw();
}
}
} finally {
if (canvas != null) {
surfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
}
} |
|
в вашей активити
Java | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
| ...
private MainSurfaceView mainView;
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
...
mainView = new MainSurfaceView(this);
mainView.setOnTouchListener(touchListener);
setContentView(mainView); |
|
0
|