소스코드는 엄청 간단합니다.



==================================== class TimeGameView =================================================

public class TimeGameView extends SurfaceView implements Callback

{

Context context;

SurfaceHolder holder;

TimeGameThread tThread;

public TimeGameView(Context _context) {

super(_context);

holder = getHolder();

holder.addCallback(this);

context = _context;

tThread = new TimeGameThread(context, holder);

Log.i("Log","TimeGameView");

setWillNotDraw(false); // onDraw 호출이 안될 때 쓰면 좋다

// 쓰레드의 start는 서페이스뷰 크리에잇에서 했다.

}

protected void onDraw(Canvas canvas) {

Log.i("Log","onDraw");

try{

do{

tThread.Draw(canvas); // 쓰레드의 캔버스를 그린다.

invalidate();

}while(true);

}catch(Exception e){}

}



==================================== class TimeGameView =================================================



public class TimeGameThread extends Thread{

Context context;

SurfaceHolder holder;

TimeGameView tView;

Rect timeRect; // 시간 막대

Paint p; // 막대 색깔

public TimeGameThread(Context _context, SurfaceHolder _holder)

{

context  = _context;

holder = _holder;

// 막대 위치, 색깔 초기화

timeRect = new Rect(0, 0, 200, 20);

p = new Paint();

p.setColor(Color.RED);

Log.i("Log","TimeGameThread");

}

public void run(){ // run은 시간계산 함수 추가

try{

while(true)

{

//tView.draw(canvas);

Thread.sleep(500);

}

}catch(Exception e){}

}

public void Draw(Canvas _canvas){ // 쓰레드의 캔버스

//Log.i("Log","Draw");

_canvas.drawRect(timeRect, p);

_canvas.drawCircle(10, 10, 20, p);

}


}


저는 쓰레드의 Draw함수안의 렉트와 공을 그리고 싶은데 어째선지 함수 호출은 되면서

그림은 그려지지 않습니다 ㅠㅠ 분명 onDraw도 호출되고 Draw도 호출되는데 그림은 안그려져서

막막합니다. onDraw함수의 그림은 while문이 끝나면 그려지는것 같습니다.

혹시 캔버스 잠금 기능이라던가 쓰지 않아서 이런걸까요ㅠㅠ?

캔버스 잠금 기능을 왜 쓰는지도 모르겠고 ㅠㅠㅠ아시는분 계신가요ㅠㅠ?