1
votes

i am loading images using picasso. i want to resize the image maintaining the aspect ratio. By far, i have found that when i use fit() method. it will resize the image and fill the image view( full image will show but not maintaining aspect ratio), and if i use centercrop() it will crop the centre part of the image to meet the imageview size( but in this case the aspect ratio remains same). i want both to happen. in my XML the height of the image view is 200dp

Picasso.with(mcontext).setIndicatorsEnabled(true);
            Picasso.with(mcontext).load("http://192.168.0.14:1337/show_all_offers/" + current.offercover).fit().centerCrop()
                    .networkPolicy(NetworkPolicy.OFFLINE)
                    .into(holder.offercover, new com.squareup.picasso.Callback() {
                        @Override
                        public void onSuccess() {
                            Log.d("cover", "success");
                        }

                        @Override
                        public void onError() {
                            Log.d("cover", "failure");
                        }
                    });
1

1 Answers

0
votes

I am using the below code to maintain the aspect ratio. The image will get cut from the sides.

Picasso.with(ctx).load(imageURL).fit().centerCrop().placeholder(R.mipmap.fallback_image).error(R.mipmap.fallback_image).into(imageView);

This might help you.