0
public class MyBringBackSurface extends SurfaceView implements Runnable 
    {
        SurfaceHolder ourHolder;
        Thread ourThread;
        boolean isRunning=false;
        Bitmap[] bitmap={BitmapFactory.decodeResource(getResources(), R.drawable.dice1),
                BitmapFactory.decodeResource(getResources(), R.drawable.dice2),
                BitmapFactory.decodeResource(getResources(), R.drawable.dice3)

        };

        public MyBringBackSurface(Context context) {
            super(context);
            ourHolder=getHolder();

        }
        @Override
        public void run() 
        {

            while(isRunning)
            {
                if(!ourHolder.getSurface().isValid())
                    continue;
                Canvas canvas = ourHolder.lockCanvas();
                Bitmap[] bitmap={BitmapFactory.decodeResource(getResources(), R.drawable.dice1),
                        BitmapFactory.decodeResource(getResources(), R.drawable.dice2),
                        BitmapFactory.decodeResource(getResources(), R.drawable.dice3)};
                for(timer=0; timer< bitmap.length; timer++)
                {
                    canvas.drawBitmap(bitmap[timer], 10,20,null);
                }
                ourHolder.unlockCanvasAndPost(canvas);
            }   
        }
        public void pause() {
            isRunning = false;
            while(true)
            {
                try 
                {
                    ourThread.join();
                } 
                catch (InterruptedException e) 
                {   
                    e.printStackTrace();
                }
                break;
            }
            ourThread=null;
        }
        public void resume()
        {
            isRunning = true;
            ourThread= new Thread(this);
            ourThread.start();
        }

    }
}
4

1 回答 1

0

  try{
  Thread.sleep(1000);    
  canvas.drawBitmap(bitmap[timer], 10,20,null);
  }catch(InterruptedException e){
}

它符合你的答案吗?

于 2013-12-23T10:13:11.643 回答