안드로이드 개발 질문/답변
(글 수 45,052)
onDraw를 아래같이 짰는데요. 아무 에러도 없고 실행은 되는데 그림이 그려지질 않네요 ㅠ
뭐가 잘못된 걸까요 ㅠ
x,y는 센서 값입니다.
move1,2,3,4,5,6을 번갈아 가면서 나오게 하려는데 이렇게 하는게 맞는건가요??
@Override
protected void onDraw(Canvas canvas){
new Thread(new Runnable(){
Canvas canvas = null;
public void run(){
while(true){
try{
for(int i=0; i<7; i++){
canvas.drawBitmap(move1, x, y, null);
Thread.sleep(1000);
canvas.drawBitmap(move2, x, y, null);
Thread.sleep(1000);
canvas.drawBitmap(move3, x, y, null);
Thread.sleep(1000);
canvas.drawBitmap(move4, x, y, null);
Thread.sleep(1000);
canvas.drawBitmap(move5, x, y, null);
Thread.sleep(1000);
canvas.drawBitmap(move6, x, y, null);
Thread.sleep(1000);
}
}
catch(Throwable t){
}
}
}
}).start();
}
뭐가 잘못된 걸까요 ㅠ
x,y는 센서 값입니다.
move1,2,3,4,5,6을 번갈아 가면서 나오게 하려는데 이렇게 하는게 맞는건가요??
@Override
protected void onDraw(Canvas canvas){
new Thread(new Runnable(){
Canvas canvas = null;
public void run(){
while(true){
try{
for(int i=0; i<7; i++){
canvas.drawBitmap(move1, x, y, null);
Thread.sleep(1000);
canvas.drawBitmap(move2, x, y, null);
Thread.sleep(1000);
canvas.drawBitmap(move3, x, y, null);
Thread.sleep(1000);
canvas.drawBitmap(move4, x, y, null);
Thread.sleep(1000);
canvas.drawBitmap(move5, x, y, null);
Thread.sleep(1000);
canvas.drawBitmap(move6, x, y, null);
Thread.sleep(1000);
}
}
catch(Throwable t){
}
}
}
}).start();
}
쓰레드 안에서 null값인 canvas로 그림을 그린다고 생각되는데요,,
쓰레드를 왜 굳이 넣었는지는 잘 모르겠습니다.
Canvas canvas = null 라인을 아예 제거하고 해 보세요.