我正在爲平板電腦(1024x768)開發Android應用程序。我在這裏搜索並找到一些解決方案,但任何人都解決了我的問題。該應用程序有5個屏幕和每個屏幕有我加載的ImageView:Android:加載圖像時出錯:OutOfMemoryError:位圖大小超過虛擬機預算
<ImageView
android:id="@+id/imageView1"
android:layout_width="1024dp"
android:layout_height="768dp"
android:layout_centerHorizontal="TRUE"
android:src="@drawable/scene1"
/>
第一和第二屏負載不錯,但是當我嘗試加載第三個,我收到以下錯誤(每屏我通過startActivity負載這是它的佈局不是一個佈局錯誤,因爲如果我用不同的順序加載它們,我可以裝載兩個,第三個crases太):
05-28 17:03:51.774: E/AndroidRuntime(401): java.lang.RuntimeException: Unable to start activity ComponentInfo{xxx}: android.view.InflateException: Binary XML file line #10: Error inflating class <unknown>
05-28 17:03:51.774: E/AndroidRuntime(401): Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class <unknown>
05-28 17:03:51.774: E/AndroidRuntime(401): Caused by: java.lang.reflect.InvocationTargetException
05-28 17:03:51.774: E/AndroidRuntime(401): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
我試過幾件事情:
@Override
public void onPause()
{
super.onPause();
Log.i("URI", "Syste.gc");
// yada yada yada...
System.gc();
}
和
@Override
protected void onDestroy()
{
super.onDestroy();
unbindDrawables(findViewById(R.id.RootView));
System.gc();
}
private void unbindDrawables(View view)
{
if (view.getBackground() != null)
{
view.getBackground().setCallback(null);
}
if (view instanceof ViewGroup)
{
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++)
{
unbindDrawables(((ViewGroup) view).getChildAt(i));
}
((ViewGroup) view).removeAllViews();
}
}
但我總是得到錯誤。
圖像是PNG,其重量低於50k。
有什麼建議嗎?
謝謝!
圖像的文件大小几乎是不相關的。像素的寬度和高度是多少? –
1024x768是寬度和高度,但我需要圖像來填充所有屏幕... – oriolpons