0
我在加載背景圖片之前加載另一張圖片時出現錯誤。 logcat指向內存錯誤,但背景只有17kb大小。Android背景圖片錯誤
在這裏,在事件
的序列碼package com.firm.armouredassault;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.os.Bundle;
public class StartNewGame extends Activity {
MyGame ourView;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
//setContentView(R.drawable.canvas);
ourView = new MyGame(this);
setContentView(ourView);
}
}
MyGame.java:
package com.firm.armouredassault;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.view.View;
public class MyGame extends View {
Bitmap BTank, TShell;
public MyGame(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
canvas.drawBitmap(BitmapFactory.decodeResource(getResources(),
R.drawable.bluetanksm), 10, 200, null);
}
}
我知道問題是與行//setContentView(R.drawable.canvas);公共類StartNewGame的擴展活動 – anwarma
任何想法,我應該如何加載我用作背景畫布的背景圖像 – anwarma