Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageView with wrap_content height shows very skinny / cropped photo instead of full height

Tags:

android

xml

I have a screen where the user can read an article (with large photo at the top.

It's general structure is:

LinearLayout -> ScrollView -> LinearLayout -> ImageViews,TextViews...etc

The ImageView I'm having problems with is the large image at the top (below the Article's title, but above it's text:

        <ImageView
            android:id="@+id/article_photo"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@color/super_light_gray"
            android:scaleType="centerCrop"
            android:contentDescription="@string/articlePhoto"
            android:cropToPadding="true"
            android:layout_marginBottom="10dp"
            android:padding="1dp"/>

The problem is, the photos appear, but are cropped vertically A LOT so that even vertical-oriented photos show up very skinny and wide. I assumed that "wrap_content" should make it the full height of the photo... but I'm obviously wrong :)

How can I make the photo show up full width (already working), but also full height?

I'm using the UniversalImageLoader to load the images:

        if(lrgPhoto != null && !lrgPhoto.filepath.equals(""))
        {
            imageLoader.displayImage(
                "http://img.mysite.com/processes/resize_android.php?image=" + lrgPhoto.filepath + "&size=640&quality=90",
                imageView,
                imgDisplayOptions
                );
            imageView.setVisibility(View.VISIBLE); //show photo
        }
        else
        {
            imageView.setVisibility(View.GONE); //hide photo
            imageView.invalidate();
        }

Edit:

If I change 'scaleType' to 'fitXY', then the image shows correct dimensions without being cropped, but then it's not full-width. Is there a way I can have both full-width AND not-cropped strangely?

It appears the "crop" is because it's using the original height of the image for the height, but it's enlarging the image to fit full-width...

like image 240
Dave Avatar asked Nov 27 '22 07:11

Dave


1 Answers

Add this to the imageview xml:

android:adjustViewBounds="true"
like image 190
George Mincila Avatar answered Dec 17 '22 03:12

George Mincila