for loop显示最后一张图片。我希望在画布上逐个图像...在相同的x和y轴上

时间:2013-05-17 07:18:55

标签: android

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();
        }

    }
}

1 个答案:

答案 0 :(得分:0)

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

它符合你的答案吗?