SurfaceView 에서 drawText를 이용해 글자를 직으려고 합니다.
책 및 다른 여러 예제를 보아도 제가 만든 코드에는 이상이 없는 것 같습니다
하지만, 실제로를 글자도 변경된 배경색도 보이지 않습니다.
디버깅 상에 값은 정상적으로 들어 오는 것은 확인했습니다.
이거 무슨 문제인지 아래 코드를 보시고 답변 부탁 드립니다.
public class ViewDesktop extends SurfaceView implements Callback {
private ImageThread thread;
final static String TAG = "ViewDesktop";
public static boolean bStart = false;
public static String idata1;
public ViewDesktop(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
private void init(Context context) {
SurfaceHolder holder = getHolder();
holder.addCallback(this);
thread = new ImageThread(context, holder);
}
public void surfaceCreated(SurfaceHolder holder) {
Log.d(TAG, "surfaceCreated");
bStart = true;
thread.start();
}
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { }
public void surfaceDestroyed(SurfaceHolder holder) {
try {
Log.d(TAG, "surfaceDestroyed");
bStart = false;
thread.join();
} catch (InterruptedException ex) { }
}
class ImageThread extends Thread {
SurfaceHolder mHolder;
private int mCount = 0;
public ImageThread(Context context, SurfaceHolder surfaceHolder) {
mHolder = surfaceHolder;
}
public void run() {
while (bStart) {
Canvas c = null;
try {
c = mHolder.lockCanvas(null);
synchronized (mHolder) {
doDraw(c);
mCount++;
sleep(100);
}
} catch (InterruptedException ex) {
Log.e("ThreadAnimationView", "Exception in thread.", ex);
} finally {
if (c != null) {
mHolder.unlockCanvasAndPost(c);
}
}
}
}
//text를 그린다.
private void doDraw(Canvas canvas) {
try{
Paint Pnt = new Paint();
canvas.drawColor(color.darker_gray);
Pnt.setAntiAlias(true);
Pnt.setTextSize(20);
Pnt.setColor(color.holo_red_light);
canvas.drawText("test...", 10, 100, Pnt);
Log.d(TAG, "test...");
}
catch(Exception e)
{
Log.e(TAG, "Exception in thread.", e);
}
}
}
}




아 문제가 있군요...
import android.R.color; 를 사용 하면 안되고
import android.graphics.Color; 를 사용 해야 하는군요 *^^*
이걸 몰랐네요 ㅎㅎㅎ