【发布时间】:2012-10-26 13:35:43
【问题描述】:
我在扩展 View 类的类中使用 onDraw(Canvas canvas) 方法创建了一个自定义视图。我正在使用 invalidate() 方法每 2 秒刷新一次视图。但是现在我想在之后停止刷新视图一段时间后说 120 秒。我将如何停止 invalidate() 方法。任何建议或帮助将不胜感激。
编辑
这是我的代码:-
public GameView(Context context){
super(context);
Display display = ((WindowManager)context.getSystemService(
Context.WINDOW_SERVICE)).getDefaultDisplay();
}
@Override
public void draw(Canvas canvas) {
// TODO Auto-generated method stub
super.draw(canvas);
int x = 0;
int y = 0;
bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
int imageWidth = bmp.getWidth();
int imageHeight = bmp.getHeight();
int width = display.getWidth();
System.out.println("Width = " +width);
int height = display.getHeight();
System.out.println("Height = " +height);
Random randomX,randomY;
randomX = new Random();
randomY = new Random();
x = randomX.nextInt(width - imageWidth);
System.out.println("X = " +x);
y = randomY.nextInt(height - imageHeight);
System.out.println("Y = " +y);
Rect dst = new Rect(x , y , x + imageWidth , y + imageHeight);
canvas.drawBitmap(bmp, null , dst , null);
System.out.println("dst = " +dst);
try{
Thread.sleep(1000)
}
catch(Exception e){
}
invalidate();
}
【问题讨论】:
-
从哪里调用 invalidate()?
-
你能发布一些示例代码吗?
-
请看修改后的内容。
-
我不相信没有人能回答这个问题。
标签: android android-canvas android-view