Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resizing image with picasso

Hey everyone I have been running into an issue with Picasso. I am trying to load an image from sound cloud but it keeps appearing stretched or very small. Here is my XML

        <ImageView
            android:id="@+id/album_cover_art"
            android:layout_width="300dp"
            android:layout_height="200dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="@dimen/fragment_content_item_top_margin"
            android:scaleType="centerInside"
            android:contentDescription="@string/content_description_image_placeholder"
            android:src="@drawable/placeholder" />

I tried to use picasso's resize and center inside but the image appears small.

Picasso.with(getContext()).load(mSelectedTrack.getArtworkURL()).resize(800,300).centerInside().into(mAlbumCoverArt);

Using picasso's resize and center crop maintains the image view size but leads to the image appearing stretched.

Picasso.with(getContext()).load(mSelectedTrack.getArtworkURL()).resize(800,300).centerCrop().into(mAlbumCoverArt);

Any ideas on a way to do this that is easier than writing a function to resize it myself ?

like image 720
Doug Ray Avatar asked Feb 03 '26 00:02

Doug Ray


1 Answers

I avoided image stretching using :

.resize(800,0)

Passing 0 as second parameter it preserved the image proportions.

Hope it helps

like image 113
Flavio Gasparini Avatar answered Feb 05 '26 13:02

Flavio Gasparini



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!