View 클래스를 확장하는 클래스에서 onDraw (Canvas canvas) 메서드를 사용하여 사용자 정의보기를 만들었습니다. 나는 2 초마다 내보기를 새로 고치기 위해 invalidate() 메서드를 사용하고 있습니다. 그러나 이제 일부보기 후에보기를 새로 고치고 싶습니다. 120 초 후에 말하는 시간. 어떻게 invalidate() 메서드를 멈 춥니 다. 어떤 제안이나 도움을 주시면 감사하겠습니다.사용자 정의보기 새로 고침을 중지하는 방법은 무엇입니까?
편집
여기 내 코드입니다 : - 당신은 단지 카운터 (예를 들어, INT의 myCounter)를 사용하여 각주기에서 2 값을 증가시킬 필요가
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()를 호출합니까? – Flo
몇 가지 샘플 코드를 게시 할 수 있습니까? – nik431
편집 된 내용을 참조하십시오. – himanshu