安卓:错误加载图片:OutOfMemoryError错误:位图大小超过VM预算 [英] Android: Error loading images: OutOfMemoryError: bitmap size exceeds VM budget

查看:226
本文介绍了安卓:错误加载图片:OutOfMemoryError错误:位图大小超过VM预算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发的平板电脑(1024×768)的Andr​​oid应用程序。我搜索,在这里找到了一些解决方案,但任何人都解决了我的问题。该应用程序有5个屏幕,每个屏幕上有我加载ImageView的:

I'm developing an Android Application for a tablet (1024x768). I searched and find some solutions here, but anyone solved me the problem. The application has 5 screens and each screen has an ImageView that I load:

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="1024dp"
    android:layout_height="768dp"
    android:layout_centerHorizontal="TRUE"
    android:src="@drawable/scene1"
    />

第一个和第二个屏幕负荷好,但是当我尝试加载第三个,我收到以下错误(每一个屏幕,我通过startActivity加载的它的布局。这不是一个布局错误,因为如果我加载它们不同的顺序,我可以装载两个,第三个也crases):

The first and the second screen loads good, but when I try to load the third one, I get the following errors (Every screen I load by startActivity which its layout. It's not a layout error, because if I load them with a different order, I can load two and the third one crases too):

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

我试过几件事情:

I tried several things:

 @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();
    }
}

但我总是得到错误。

but I always get the error.

该图像是PNG其重量低于50K。

The images are PNG and its weight is lower than 50k.

有什么建议?

谢谢!

推荐答案

尝试在OnCreate加载图像()方法,而不是从XML加载它。

Try to load the image in the onCreate() method instead of loading it from the XML.

你试过先阅读图像的尺寸和类型,然后加载图像的缩小版本?

Have you tried to first read the dimensions and type of the image, and then load a scaled down version of that image?

由于href=\"http://developer.android.com/training/displaying-bitmaps/load-bitmap.html\" rel=\"nofollow\"> Android开发者资源建议

As the Android developer resources suggest.

这篇关于安卓:错误加载图片:OutOfMemoryError错误:位图大小超过VM预算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆