0
votes

I'm dealing with a problem with the RecycleView while I'm scrolling and loading images from the web. The size of the image PLUS the behaviour of the ImageView component (width = match pratent, height = wrap content) determines the height of the child. I thought that a good workaround for it was to ask the image height and width from the server. That way I would be able to resize the child at the very moment that it is created, avoiding the odd behaviour of resizing after the image is loaded. In order to do that, I started creating Bmp drawables with the correct size of the image that would be loaded and putting it as placeholder using the picasso (placehold(Drawable)).

With that, I've fixed the resize problem, but then I started to get OutOfmemory because of the creation of the BMP. is there a better approach to if it?

1

1 Answers

0
votes

Have you ever try BitmapFactory.Options? There is a way to fetch the image attributes before loading entire bitmap data as :

BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(getResources(), R.id.myimage, options);
int imageHeight = options.outHeight;
int imageWidth = options.outWidth;
String imageType = options.outMimeType;

ref https://developer.android.com/topic/performance/graphics/load-bitmap.html