Android : How to display random images on screen android

on Saturday, July 5, 2014


I have 7 images in the drawable folder. I would like to display them randomly on the screen. I am new to working with graphics. Right now it shows just one image on the screen.How can I display random images on the screen? Thanks



public class MyGraphics extends SurfaceView implements Runnable {

SurfaceHolder ourHolder;
Thread ourThread = null;
Boolean isRunning = true;
int[] images = new int[]{R.drawable.img1, R.drawable.img2, R.drawable.img3, R.drawable.img4, R.drawable.img5, R.drawable.img6,R.drawable.img7};


public void run() {



while(isRunning){

if(!ourHolder.getSurface().isValid())
continue;

Canvas ourCanvas = ourHolder.lockCanvas();
ourCanvas.drawRGB(0, 0, 0);

Bitmap img_blue = BitmapFactory.decodeResource(getResources(), R.drawable.mg1);
ourCanvas.drawBitmap(img_blue, 0, 0, null);

ourHolder.unlockCanvasAndPost(ourCanvas);




}



}

0 comments:

Post a Comment