Search code examples
androidimageviewpicasso

Android Picasso handling on orientation changed


I've an adapter which loads images to an ImageView with the Picasso until here everything is ok. The problem is I'm handling by myself the orientation changes:

android:configChanges="orientation|keyboardHidden|screenSize"

and i cant make to Picasso reload the image and fit it correctly in the imageView after the orientation changed.

if (imageUrlString == null) {
        Picasso.with(context).load(R.drawable.image_adega).fit().centerCrop()
                .into(headerHolder.img_store);

    } else {

        Picasso.with(context).load(imageUrlString).fit().into(headerHolder.img_store);
    }

And in my activity:

@Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        if (adapter != null) {
            adapter.reloadPicasso(getActivity());
        }
    }

XML:

 <ImageView
    android:id="@+id/img_store"
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:layout_centerHorizontal="true"
    android:adjustViewBounds="false"/>

Thanks


Solution

  • You need to alter your layout file to specify the scaling type.

    Add

    android:scaleType="centerCrop" 
    

    to your layout XML file and then when the device is rotated the ImageView will automatically scale the image. You don't need to manually reload the ImageView using Picasso.