nostra13 / Android-Universal-Image-Loader

Powerful and flexible library for loading, caching and displaying images on Android.
Apache License 2.0
16.78k stars 6.1k forks source link

Image inside imageView with centerCrop being resized #1021

Open daverdalas opened 9 years ago

daverdalas commented 9 years ago

Hey, I have a little problem with the tool, which for a long time can't resolve. In my application I fill listView with ImageView's. Both the height of the listView what imageView is set to the entire height of the screen. ImageView is set to scaleType on centerCrop. I am loading images using a Universal Image Loader with:

     .imageScaleType (ImageScaleType.EXACTLY)

Unfortunately, height of imageView shall is changed so as to maintain the aspect ratio of the image. I wish the image was high on the entire screen and on szerkość was hiding outside the screen. I tried different settings of ImageScaleType but the image always is reduced.

My list code:

    <android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!-- The main content view -->
    <ListView
        android:id="@+id/WallpapersListView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"/>
    </android.support.v4.widget.DrawerLayout>

ImageView code:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent">
    <ImageView
        android:id="@+id/wallpaper_image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        android:src="@drawable/test"
         />
    <TextView
        android:id="@+id/wallpaper_date_for_use"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dip"
        android:padding="12dip"
        android:background="#AA000000"
        android:textColor="#ffffffff"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:gravity="center"
        android:textStyle="bold"
        android:text="Date of use" />
    </LinearLayout>

Uniwersal Image Loader settings:

    imageLoaderOptions = new DisplayImageOptions.Builder()
                .imageScaleType(ImageScaleType.EXACTLY)
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .build();

Image loading code:

    imageLoader.displayImage(
                    wallpapers.get(position).getFullHDUrl()//the drawable
                    , currentWallpaperViewHolder.imageViewWallpaper//the image view
                    , imageLoaderOptions);//the display options

Some time ago I asked a similar question on stackoverflow but I didn't get the correct answer :( http://stackoverflow.com/questions/30335029/android-image-display-full-height-loaded-asynchronously Maybe someone here can help me :)

TomIsYourName commented 9 years ago

@daverdalas I got the same issue when loading thumbnail, have got the solution ?

daverdalas commented 9 years ago

@TomIsYourName Adjusting the height programmatically for ImageView after loading of image is the only solution that worked for me.

TomIsYourName commented 9 years ago

@daverdalas Thanks, will try