我開始2在相同的活動AnimationDrawables,我有一個內存錯誤。 這非常令人驚訝,因爲我減小了圖像的大小(寬度=屏幕寬度),並且我無法將其降低得更多,因爲質量會降低。舉例來說,如果我做的寬度=屏幕/ 2的寬度,它wortks但質量是可怕的Android:內存錯誤和位圖的大小/質量
在它被寫入
02-19 10:56:44.769: E/dalvikvm-heap(3118): 383916-byte external allocation too large for this process.
02-19 10:56:44.809: E/GraphicsJNI(3118): VM won't let us allocate 383916 bytes
02-19 10:56:44.809: W/dalvikvm(3118): threadid=1: thread exiting with uncaught exception (group=0x40018560)
02-19 10:56:44.819: E/AndroidRuntime(3118): FATAL EXCEPTION: main
02-19 10:56:44.819: E/AndroidRuntime(3118): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
的logcat的,我不認爲我有內存泄漏,但檢查這篇文章http://android-developers.blogspot.de/2009/01/avoiding-memory-leaks.html我試圖檢測潛在的內存泄漏,但在我看來沒有。
我真的需要一些幫助,因爲它不是我在這個項目中的第一個內存錯誤,我總是很難處理這個問題。
這裏是我的代碼:?
private void startAnimation(AnimationDrawable animation1,AnimationDrawable animation2){
int drawables[] = new int[] {R.drawable.fire1,R.drawable.fire2,R.drawable.fire3,R.drawable.fire4,R.drawable.fire5,R.drawable.fire6,R.drawable.fire7,R.drawable.fire8,R.drawable.fire9,R.drawable.fire10down2,R.drawable.fire11down2,R.drawable.fire12down2,R.drawable.fire13down2,R.drawable.fire14down2,R.drawable.fire15down2,R.drawable.fire16down2};
int drawables2[] = new int[] {R.drawable.fire14down2,R.drawable.fire14down2,R.drawable.fire14down2,R.drawable.fire14down2,R.drawable.fire14down2,R.drawable.fire14down2,R.drawable.fire14down2,R.drawable.fire14down2,R.drawable.fire14down2,R.drawable.fire10up,R.drawable.fire11up,R.drawable.fire12up,R.drawable.fire13up,R.drawable.fire14up,R.drawable.fire15up,R.drawable.fire16up};
bitmapDrawable = new BitmapDrawable[drawables.length];
bitmapDrawable2 = new BitmapDrawable[drawables2.length];
for (int i=0;i<drawables.length;i++) {
bitmapDrawable[i]=new BitmapDrawable(decodeSampledBitmapFromResource(getResources(), drawables[i],width));
Log.w("BITMAP","i="+i);
bitmapDrawable2[i]=new BitmapDrawable(decodeSampledBitmapFromResource(getResources(), drawables2[i],width));
animation1.addFrame(bitmapDrawable[i],50);
animation2.addFrame(bitmapDrawable2[i],50);
}
animation1.setOneShot(true);
animation2.setOneShot(true);
image2.setLayoutParams(params);
image2.setImageDrawable(animation1);
image2.post(new Starter(animation1));
image3.setLayoutParams(params);
image3.setImageDrawable(animation2);
image3.post(new Starter(animation2));
}
class Starter implements Runnable {
AnimationDrawable animation = new AnimationDrawable();
public Starter(AnimationDrawable animation) {
this.animation = animation;
}
public void run() {
animation.start();
}
}
我怎麼能降低位圖的重量(如果有必要的問題可能某處else_並保持theimages的質量我看不出哪裏是這個問題,我只用30幅,其他應用程序使用更多更多
正如我所說當我減小尺寸質量不滿足我所以我想要其他解決方案 – morg 2013-02-19 13:10:35