I have next problem: To avoid OutOfMemoryError i'm loading my big images into ImageViews using Picasso in such way:
public static RequestCreator picasso(final Context context, final int resourceId) {
return Picasso.with(context)
.load(resourceId)
.fit()
.centerCrop()
.noFade();
}
And in activity or fragment, i'm loading image into ImageView
final ImageView backgroundImage = (ImageView) root.findViewById(R.id.background_image);
Util.picasso(getActivity(),R.drawable.background_soulmap)
.into(backgroundImage);
However, i have two problems:
- Image loads with some delay (but i need to load it immideatly)
centerCrop() is not what i need in some cases.
How can i implement something like topCrop() or bottomCrop()? I've tried https://github.com/cesards/CropImageView library, but i'm getting NullPointerException in setFrame() method (getDrawable() returns null), because image did not load yet. Thanks in advance!
you have to choose: (a) memory efficient delay or (b) instant but probable OOM. And I said that by experience, the app I have on the Play Store have a little delay while Picasso is processing it. It's just how it works.
then you should load the image
into()
aTarget
. The target will receive theDrawable
in the UI thread, from there you can set it up inside the ImageView (using thesetScaleType
) or as a background anyway you want. Maybe even using anInsetDrawable
to adjust position.