응용 프로그램을 시작할 때 모두 정상입니다. 하지만 다음 활동으로 가서 SurfaceView를 다시 방문하면 black
처럼 보입니다. 디버깅 할 때 캔버스에서 그려야 할 선을 볼 수 있지만 아무것도 표시되지 않습니다. 당신은 내가 이력서를 사용하여 기능을 일시 정지하고있어 보는 바와 같이표면보기 재개로 인해 검은 색 화면이 표시됩니다.
public class DrawView extends SurfaceView implements Runnable
{
Thread thread = null;
SurfaceHolder holder;
Bitmap background;
Canvas canvas;
Matrix matrixUP = new Matrix();
Matrix matrixDOWN = new Matrix();
boolean ok = false;
public DrawView(Context context)
{
super(context);
holder = getHolder();
}
public void run()
{
while(ok)
{
if(!holder.getSurface().isValid())
{
continue;
}
watch_hand = Bitmap.createScaledBitmap(watch_hand, width/4, height/6, false);
watch_hand_down = Bitmap.createScaledBitmap(watch_hand_down, width/4, height/6, false);
background = BitmapFactory.decodeResource(getResources(), R.drawable.needles);
background = Bitmap.createScaledBitmap(background, width, height/2+20, false);
canvas = holder.lockCanvas();
matrixUP.setTranslate(CENTER_X - watch_hand.getWidth()/2, height/4 - watch_hand.getHeight() - 40);
matrixUP.preRotate((float) degreUP , watch_hand.getWidth()/2 , watch_hand.getHeight()-10);
matrixDOWN.setTranslate(CENTER_X - watch_hand_down.getWidth()/2, height/2 - watch_hand_down.getHeight() - 20);
matrixDOWN.preRotate((float) degreDOWN , watch_hand_down.getWidth()/2 , 10);
canvas.drawARGB(255, 255, 255, 255);
canvas.drawBitmap(background, 0, 0, null);
canvas.drawBitmap(watch_hand, matrixUP, null);
canvas.drawBitmap(watch_hand_down, matrixDOWN, null);
holder.unlockCanvasAndPost(canvas);
}
}
public void pause()
{
ok = false;
while(true)
{
try
{
thread.join();
}catch (InterruptedException e)
{
e.printStackTrace();
}
break;
}
thread = null;
}
public void resume()
{
ok = true;
thread = new Thread(this);
thread.start();
}
}
:
다음은 내 코드입니다. 그들은 onCreate에서 호출됩니다. 왜 그런 일이 발생하며 어떻게 해결할 수 있습니까?
감사합니다.
제 경우에도 똑같은 일이 일어나고 있습니다. 해결책을 공유 할 수 있습니까? –