Mayukh Nair
Mayukh Nair

Reputation: 653

Picasso - how to resize placeholder

I'm using a 128x128 circular image, animated by a drawable as a placeholder in Picasso.

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/loading_circle"
    android:pivotX="50%"
    android:pivotY="50%" />

And this is how my Java code implements it:

Picasso.with(context)
                        .load(message.getMediaUrl())
                        .config(Bitmap.Config.ARGB_4444)
                        .resize(w, h)
                        .onlyScaleDown()
                        .centerCrop()
                        .placeholder(R.drawable.progresscircle)
                        .into(messageImage);

Note that the image sizing parameters above are required by the final image that is loaded into my chat adapter's imageview.

The problem is, Picasso is blowing up and cropping the placeholder like this:

enter image description here

How can I set separate parameters for the placeholder to be suitably sized? Also, what exact parameters would be helpful?

Upvotes: 9

Views: 7106

Answers (4)

Navneet Krishna
Navneet Krishna

Reputation: 5017

As mentioned here,

  1. Inside your imageviews xml set android:scaleType="centerInside"

  2. Then add fit().centerCrop().noFade() like this

                     Picasso.with(context)
                    .load(message.getMediaUrl())
                    .config(Bitmap.Config.ARGB_4444)
                    .resize(w, h)
                    .onlyScaleDown()
                    .centerCrop()
                    .fit()
                    .noFade()
                    .placeholder(R.drawable.progresscircle)
                    .into(messageImage);
    

Upvotes: 3

Anurag Shrivastava
Anurag Shrivastava

Reputation: 692

in XML where you set ImageView add.

android:scaleType="centerCrop"

It may work. you can set fitXY instead of centerCrop if it is not working.

Upvotes: 6

Jayanth
Jayanth

Reputation: 6307

change your Picasso call to this,

Picasso.with(context)
                    .load(message.getMediaUrl())
                    .config(Bitmap.Config.ARGB_4444)
                    .fit()
                    .centerCrop()
                    .placeholder(R.drawable.progresscircle)
                    .into(messageImage);

Upvotes: 0

Dhruvi
Dhruvi

Reputation: 1981

Try this:

 Picasso
.with(context)
.load(message.getMediaUrl())
.fit()
// call .centerInside() or .centerCrop() to avoid a stretched image
.into(messageImage);

Upvotes: 0

Related Questions