Scaling an image to max available width, keeping aspect ratio and avoiding ImageView extra space Scaling an image to max available width, keeping aspect ratio and avoiding ImageView extra space android android

Scaling an image to max available width, keeping aspect ratio and avoiding ImageView extra space


<ImageView        android:id="@+id/game"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:scaleType="centerCrop"        android:adjustViewBounds="true"        android:src="@drawable/ic_game"         />

this works for me. Full width of parent and center crop to keep aspect ratio


It's so simple. Just make the width fill_parent and height wrap_content. Here is the I figured it out.

<ImageView    android:id="@+id/game"    android:layout_width="fill_parent"    android:layout_height="wrap_content"    android:scaleType="centerCrop"    android:adjustViewBounds="true"    android:src="@drawable/ic_game"     />


In my view, this ImageView extra layout is a bug. I had the same thing happen. As a result, text that I wanted to follow the green_square followed the extra layout. So what I did was specify the text relative to the bottom of the screen. That way, the text would go over the extra layout. I admit, it wasn't the best solution, but it looks much better than having a huge space between the green_square and the text.