Picasso crop to a view

Fricken Hamster picture Fricken Hamster · May 9, 2015 · Viewed 18.8k times · Source

How would I use picasso to crop an image to an ImageView?

Default seems to scale it down so the whole thing shows fit seems to stretch it. Centercrop by itself breaks. fit centercrop seems to be the same as just fit

Answer

Lazy Ninja picture Lazy Ninja · May 9, 2015

Try using centerCrop()

Picasso.with(mContext)
.load(url)
.centerCrop()
.resize(yourImageView.getMeasuredWidth(),yourImageView.getMeasuredHeight())
.error(R.drawable.error)
.placeholder(R.drawable.blank_img)
.into(yourImageView);

You have to add addOnPreDrawListener listener otherwise you will get 0 for width and height when the imageview is not drawn. Go here for details on how to use addOnPreDrawListener.