캔버스를 사용하여 표면 뷰에 텍스트를 그리려합니다. 문제는 각 호출 후에 표면보기가 재설정되지 않는 것입니다. 이전에 그려진 모든 것은 다시 그려 질 것입니다. 그래서, 제가 텍스트를 그릴 때마다 그 위치가 바뀌면 캔버스가 지워지지 않기 때문에 그 텍스트의 긴 흔적이 생깁니다.표면보기 문제 드로잉
내가 뭘 잘못하고 있니?
public class Test1Activity extends Activity {
private Draw drawText;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
drawText = new Draw(this);
setContentView(drawText);
}
public class Draw extends SurfaceView implements Runnable {
Thread thread = null;
SurfaceHolder surfaceHolder;
volatile boolean running = false;
private int i;
public Draw(Context context) {
super(context);
// TODO Auto-generated constructor stub
surfaceHolder = getHolder();
running = true;
thread = new Thread(this);
thread.start();
}
public void run() {
// TODO Auto-generated method stub
while (running) {
if (surfaceHolder.getSurface().isValid()) {
Canvas canvas = surfaceHolder.lockCanvas();
Paint paint = new Paint();
paint.setColor(Color.RED);
i++;
if(i > 240)
i = 1;
canvas.drawText("Hello",i , 60, paint);
surfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
}
}
public class Test1Activity extends Activity {
private Draw drawText;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
drawText = new Draw(this);
setContentView(drawText);
}
public class Draw extends SurfaceView implements Runnable {
Thread thread = null;
SurfaceHolder surfaceHolder;
volatile boolean running = false;
private int i;
public Draw(Context context) {
super(context);
// TODO Auto-generated constructor stub
surfaceHolder = getHolder();
running = true;
thread = new Thread(this);
thread.start();
}
public void run() {
// TODO Auto-generated method stub
while (running) {
if (surfaceHolder.getSurface().isValid()) {
Canvas canvas = surfaceHolder.lockCanvas();
Paint paint = new Paint();
paint.setColor(Color.RED);
i++;
if(i > 240)
i = 1;
canvas.drawText("Hello",i , 60, paint);
surfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
}
감사합니다!