このサイトで多くの回答を見つけましたが、機能していないか、単一のケースだけです。私の場合:
- 画像を読み込んで ImageView に表示したいと思います。
- ImageView の幅は、可能な限り最大にする必要があります: 親レイアウトの幅。
- 高さは、縦横比を維持しながら画像を再スケーリングできる高さでなければなりません。
これをどのように達成しますか?内部に ImageView を含む私のレイアウトを次に示します (現在、fitXY を使用していますが、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>