question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to scale bitmap to fit image view width and height

See original GitHub issue

First of all millions of thanks,for this awesome and magnificent library. This is indeed a boon to Android Community. Right now I am using this library for my project where there are 1: GridView with 3 columns 2:GridView with 2 columns 3: ListView.

All these view,loads the same image from the server. First ,GridView with 3 columns is shown and then with 2 columns and finally a ListView. The loaded bitmap fits easily (i.e. takes entire image view width and height) on GridView,but on ListView the loaded bitmap only matches the height of ImageView not the width. The ImageView size on ListView is comparatively larger than that of GridView. So far following is my configuration

Picasso.with(context).load(item.imageUrls.get(0)).fit()
                .into(holder.productImageView);
Picasso.with(context).load(item.postedProfileImage)
                .placeholder(R.drawable.image_load_bg).fit()
                .into(holder.userImageView);

And on Layout of ImageView

<ImageView
        android:scaleType="fitXY"/>

Should I go for Custom Transformation or calculate ImageView width and height and then use resize property of Picasso. Or is there anything I have wrongly implemented.

Lastly,very very great work.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
dnkoutsocommented, Aug 29, 2013

If you are using Picasso 2.0, fit() will automatically wait for your view to be measured and essentially becomes a “delayed” resize(width, height) operation under the hood.

Can you provide a screenshot of how it looks on the ListView?

0reactions
dnkoutsocommented, Sep 2, 2013

Not a problem. Images probably look a bit better because of #220 change. The change has been merged but not yet released. It will be part of our next release, which is probably going to be version 2.0.1 as a minor update.

The sample app is also available here if you clone the repo. It’s in picasso-sample. You can change urls (thats what I did) and use it as a playground to test Picasso. It has a few samples of common cases that most devs need in their apps. Check it out.

I am closing this for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fit image into ImageView, keep aspect ratio and then resize ...
The Below code make the bitmap perfectly with same size of the imageview. Get the bitmap image height and width and ...
Read more >
Working with the ImageView | CodePath Android Cliffnotes
If we need to resize a Bitmap, we can call the createScaledBitmap method to resize any bitmap to our desired width and height:...
Read more >
Scale a bitmap to fit height or width | by JPARDOGO | Medium
Fit & resize. This function will wait until the ImageView has been measured and resize the image to exactly match its size. After...
Read more >
How to Resize a Bitmap in Android? - GeeksforGeeks
Step 1: Create a New Project in Android Studio · Step 2: Working with the activity_main.xml file · Step 3: Add image to...
Read more >
ImageView.ScaleType - Android Developers
Center the image in the view, but perform no scaling. ... image uniformly (maintain the image's aspect ratio) so that both dimensions (width...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found