I have found lots of answers in this site but they are not working or just for single cases. In my case:
- I would like to load an image and show it into a ImageView.
- The width of the ImageView must be the maximum possible: parent layout width.
- The height must be the one that allows re-scale the image maintaining the aspect ratio.
How do achieve this? Here is my layout with the ImageView inside (currently I have been using fitXY but the image does not preserve the aspect ratio, even if using adjustViewBounds:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layoutPictureGalleryItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:background="#E0E0DE"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
tools:ignore="ContentDescription" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#FFFFFF" >
<TextView
android:id="@+id/textName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="esto es una prueba para ver cómo queda el layout"
android:textColor="#000000"
android:textSize="12sp"
android:typeface="serif"
android:padding="2dp" />
<TextView
android:id="@+id/textDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:padding="2dp" />
</LinearLayout>
</LinearLayout>