我在网格中有几张图像。看起来像这样:[http://cdn.thenextweb.com/wp-content/blogs.dir/1/files/2013/06/jolla4.jpg][1]
我没有使用 android Gridview,而是使用了画布,因为需要对图标进行动画处理。我读到我需要将画布用于游戏。
我正在使用 SurfaceView(结合线程)在屏幕上绘制图像。
class MySurface extends SurfaceView implements SurfaceHolder.Callback {
@Override
public void onDraw(Canvas canvas) {
//here i create the bitmaps and draw the icons on the screen.
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
thread.setRunning(true);
thread.start();
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
boolean retry = true;
thread.setRunning(false);
while (retry) {
try {
thread.join();
retry = false;
} catch (InterruptedException e) {}
}
}
这一切都很好。使用以下代码从我的主要活动中调用 Mysurface:
setContentView(new MySurface());
问题是表面视图的画布是随机重绘的。我想这样做,这样我就可以决定何时重绘画布以及重绘多少次。如何从主要活动中调用 onDraw 函数?我不知道该怎么做。
我知道线程已经完成
mySurface.onDraw(c);