正方形の画像があります (ただし、この問題は長方形の画像にも当てはまります)。縦横比を維持しながら、必要に応じて画像を拡大して親を埋めるために、画像をできるだけ大きく表示したいと考えています。画像は ImageView より小さいです。問題は、画像を引き伸ばして、ImageView の高さと幅を「一致」させることができないことです。
これは私の XML レイアウト ファイルです。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<ImageView android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:layout_marginTop="10dp"/>
<TextView android:id="@+id/name"
android:layout_below="@id/image"
android:layout_alignLeft="@id/image"
android:layout_marginTop="20dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18dp"/>
<TextView android:id="@+id/name2"
android:layout_below="@id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="14dp"/>
</RelativeLayout>
複数の scaleTypes: 、、fill_parent
、の多くの組み合わせを使用しましたが、それらはすべて正しい縦横比で画像を描画しますが、実際に画像と ImageView 自体を拡大するものはありません。画面からはみ出している、ImageView 内の空白、画像が拡大縮小されていない、または画像が切り取られています。wrap_content
fitCenter
fitStart
fitEnd
centerInside
これの正しい組み合わせがよくわかりません。