我必须使用位图显示三个图像(dex5,dex6,dex7)。当我运行下面的代码时,图像会在屏幕上显示几毫秒,并且此过程不会结束。 首先如何保存更长时间的每个图像(像1秒)? 其次,我想继续这整个过程(显示每个图像1秒)30秒。如何根据时间停止这个过程?如何在使用位图时在屏幕上保存图像android
我的代码是:
public class DrawingTheImage extends View{
private Bitmap[] btm = new Bitmap[3];
int x , y;
Random rand = new Random();
int i;
public DrawingTheImage(Context context) {
super(context);
// TODO Auto-generated constructor stub
btm[0] = BitmapFactory.decodeResource(getResources(), R.drawable.dex5);
btm[1] = BitmapFactory.decodeResource(getResources(), R.drawable.dex6);
btm[2] = BitmapFactory.decodeResource(getResources(), R.drawable.dex7);
x = 0;
y = 250;
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
Random rand = new Random();
int i;
boolean j;
i = rand.nextInt(3);
if (j = rand.nextBoolean()){
canvas.drawBitmap(btm[i], 100, y, null);
}else if (j = rand.nextBoolean()) {
canvas.drawBitmap(btm[i], 200, y, null);
}else if(j = rand.nextBoolean()){
canvas.drawBitmap(btm[i], 300, y, null);
}
invalidate();
}
}
我做了你说的,但我得到这个错误:E/AndroidRuntime(946):java.lang.NullPointerException – Ankita
我修正了上述错误。但图像仍然显示为毫秒。我怎样才能让他们在屏幕上显示更长时间? – Ankita
你试过iLate的回答吗?从onDraw()删除invalidate()? – triggs