tabHost を持つ fragmentActivity があります。すべてのタブには、画面にいくつかの ButtonTable を表示するフラグメントが含まれています。次のコードは ButtonTable です。
public class ButtonTable extends Button {
private Paint paint= new Paint();
private Bitmap bmp= null;
private Table table= null;
int width= 0;
int height= 0;
boolean adjustmentForm= false;
private WeakReference<Bitmap> resizedBitmap;
public ButtonTable(Context context, Table table, int width, int height) {
super(context);
this.table=table;
this.width= width;
this.height= height;
setWidth(width);
setHeight(height);
setBitmapImage();
setBackgroundColor(INVISIBLE);
}
[...]
public void setBitmapImage(){
int resurce= R.drawable.rectangle6;
if(table.getTableType().equals("Circle6")){
resurce=R.drawable.circle6;
adjustmentForm= true;
}
if(table.getTableType().equals("Circle4")){
resurce= R.drawable.circle4;
adjustmentForm= true;
}
[...]
bmp = BitmapFactory.decodeResource(getResources(), resurce);
if(adjustmentForm){
bmp = Bitmap.createScaledBitmap(bmp, height, height, true);
}else{
bmp = Bitmap.createScaledBitmap(bmp,width, height, true);
}
resizedBitmap = new WeakReference<Bitmap>(bmp);
}
@Override
public void onDraw(Canvas canvas){
super.onDraw(canvas);
if(adjustmentForm){
canvas.drawBitmap(resizedBitmap.get(), ((width-height)/2), 0, null);
}else{
canvas.drawBitmap(resizedBitmap.get(), 0, 0, null);
}
}
}
しばらくタブ間を移動すると、約 10/15 のタブ変更の後、OutOfMemoryError のためにアプリケーションが停止します。なんで?