2011-12-26 57 views
2

我嘗試在按鈕單擊時加載動畫。我有90圖像在資源文件夾中,我嘗試加載它們,每個圖像都有約。大小50kb當我點擊按鈕開始動畫我得到異常作爲OutOfmemory。請檢查以下代碼。任何幫助將不勝感激。逐幀動畫java.lang.OutOfMemoryError:位圖大小超過虛擬機預算

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    startbtn=(Button) findViewById(R.id.myStartButton); 
    stopbtn=(Button)findViewById(R.id.myStopButton); 
    startbtn.setOnClickListener(this); 
    stopbtn.setOnClickListener(this); 
    images=(ImageView) findViewById(R.id.myImageView); 

    images.setBackgroundResource(R.drawable.demo_animation); 

    AniFrame = (AnimationDrawable)images.getBackground(); 



} 

public void onClick(View v) { 
    if(v.getId()==R.id.myStartButton) 
    { 
     AniFrame.start(); 
    }else if(v.getId()==R.id.myStopButton) 
    { 
     AniFrame.stop(); 
    } 

} 
+0

看看頁面右側的「相關」問題。你會看到這個問題已經涵蓋了廣告的噁心。 – 2011-12-27 05:33:48

+0

我看到相關的問題,但沒有得到正確的解決方案。 – 2011-12-30 10:32:41

+0

+1爲好問題。 :d – mAc 2012-01-09 08:23:17

回答

2

圖像壓縮(JPG或PNG)?我認爲,當它們被加載到內存中時,它們會轉換爲位圖格式,並使用更多內存(每個像素最多4個字節)。 這可能是你的內存不足的原因。您無法計算90x50kb的磁盤,請考慮90 x 750Kb。

相關問題