The wrap_content
in ImageViews only works if the image is already of known size, since the layout is inflated as soon as the Activity begins. And in your case your image will still be uploaded from the web.
My suggestion, since you are using Picasso, is to load the image as a Bitmap to a Target
and use the onBitmapLoaded()
callback method to determine that the image is ready, so you still in that method you can access the width and height properties of the image and resize the ImageView according to SetLayoutParams()
.
Something like this:
Target target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
if (bitmap != null) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
// OBS: Crie um LayoutParams de acordo com o ViewGroup pai da ImageView.
// No meu exemplo, estou supondo que a ImageView está dentro de um
// FrameLayout.
imageView.setLayoutParams(new FrameLayout.LayoutParams(width, height));
imageview.setImageBitmap(bitmap);
}
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {}
};
Picasso.with(this)
.load(url)
.into(target);