在android中没有绘制背景图像

时间:2011-03-04 11:31:00

标签: android android-layout

我使用以下代码绘制画布的背景图像... 但是没有绘制图像..它显示非法状态异常..任何解决方案请... 提前谢谢。

代码段

public MyView(Context c) {
    super(c);
    //mBitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888);
    backgroundBitmap=Bitmap.createBitmap(320,480,Config.ARGB_8888);
    //  mCanvas = new Canvas(mBitmap);
    backgroundBitmap=BitmapFactory.decodeResource(getResources(), R.drawable.background);
    mPath = new Path();
    mCanvas = new Canvas(backgroundBitmap);
    mBitmapPaint = new Paint(Paint.DITHER_FLAG);
}

@Override

protected void onDraw(Canvas canvas) {
    // canvas.drawColor(0xFFAAAAAA);
    //  canvas.drawBitmap(mBitmap,0,0, mBitmapPaint);
    canvas.drawBitmap(backgroundBitmap, 0, 0, mBitmapPaint);
    if(item_id==3) {
        canvas.drawText(AppModel.contents, 100, 100, mPaint);
    }
    else {
        canvas.drawPath(mPath, mPaint);
    }
}

0 个答案:

没有答案