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

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

General structure:

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

ImageView has problems with a large image at the top (below the title of the article, but above it is the 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 that photos appear, but are cropped vertically A LOT , so that even vertically oriented photos appear very thin and wide. I suggested that "wrap_content" should make it the full height of the photo ... but I'm obviously mistaken :)

How can I make a photo complete (already working), but also complete?

I use UniversalImageLoader to load 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 changed "scaleType" to "fitXY", then the image will show the correct dimensions without cropping, but then this is not the full width. Is there a way that I can have both full size and uncircumcised weird?

Cropping seems to be because it uses the original image height for the height, but enlarges the image to full width ...

+4
source share
3 answers

Add this to imageview xml:

 android:adjustViewBounds="true" 
+29
source

Change

 android:scaleType="centerCrop" 

to

 android:scaleType="fitXY" 
+1
source

I would have thought it was simple, but it looks like it might not be possible with just an XML layout:

ImageView - has a height matching width?

0
source

Source: https://habr.com/ru/post/1445099/


All Articles