开发者

How can i recycle imageView by using imagepath

Here I am storing all image paths into database. In TabHost, If i click FIND tab all images should be displayed. At that time OutOfMemoryError is coming. Please help me. It is very important for me.

    Image s = pictures.get(i);
    TableRow imageTableRow = new TableRow(ctx);
    imageTableRow.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
    ImageView imageView = new ImageView(ctx);
    Log.i("NEVERFORGET","PICTURE IMAGE PATH is : " + s.getimagePath());
    Drawable d = Drawable.createFromPath(s.getimagePath());
    imageView.setImageDrawable(d);
    imageView.setId(i);
    imageView.setLayoutParams(new TableRow.LayoutParams(100,100));
  开发者_如何学编程  imageView.setPadding(0, 10, 0, 15);


Don't use Drawable.createFromPath() as that is bound to load images at their native resolution. Doubtless these are large images, photos etc, and will therefore require vast amounts of memory once decompressed, and hence your OOM errors. Even if you're then asking them to render into a small box, they are probably fully-sized in memory.

You should instead use BitmapFactory.decodeFile() in conjunction with a suitable choice for BitmapFactory.Options.inSampleSize.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜