在Android中显示图像会导致内存不足错误

时间:2012-07-05 12:55:10

标签: android out-of-memory

我在ViewPager.显示图像显示的图像占用了大量空间。在显示少量图像后,它会抛出java.lang.outofMemoryError: Bitmap size exceeds VM bugdet.

有关可能出现的问题的任何建议?

public Object instantiateItem(View pager, int position) {

    LayoutInflater inflater = (LayoutInflater) pager.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View view = inflater.inflate(R.layout.fotopager_buttons, null);

    TextView text = ((TextView) view.findViewById(R.id.textView1));
    text.setText(Global.totalpaging_titlearray[position]);

    TextView textprice = ((TextView) view.findViewById(R.id.textprice));
    textprice.setText("SAR " + Global.totalpaging_pricearray[position]);

    TextView textdesc = ((TextView) view.findViewById(R.id.textdescription));
    textdesc.setText(Global.totalpaging_descarray[position]);

    ImageView imageView1 = ((ImageView) view.findViewById(R.id.image));
    bimage = getBitmapFromURL(Global.totalpaging_array[position]);
    imageView1.setImageBitmap(bimage);
    ((ViewPager) pager).addView(view);

    return view;
}

2 个答案:

答案 0 :(得分:0)

据我所知,您正在查看寻呼机的页面上显示图像。您的查看寻呼机持有多少页?

如果一个页面中的位图超出VM预算,请考虑调整位图大小或解码为低内存颜色格式,如RGB565或ARGB444。

如果没有代码,则无法确定您是否正确地实例化了视图寻呼机的页面。您可以发布PagerAdapter类instantiateItem(View view, int position)方法的代码吗?

答案 1 :(得分:0)

在图像非常大之前,您会遇到此问题。它们是非常高分辨率的图像,因此具有非常大的尺寸。尝试使用任何软件如photoshop减小这些图像的大小或分辨率。

相关问题