4 つの画像の行を表示するために使用している GridView があります。各画像は 200 x 200 ピクセルです。レイアウトxmlは次のとおりです。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<GridView
android:id="@+id/myGridView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:numColumns="4" >
</GridView>
</RelativeLayout>
ここでアプリを実行すると、画像は次のようになります。
ご覧のとおり、画像は画面に合わせて拡大縮小 (縮小) されています。
正しい縦横比を維持するために、画像が垂直方向と水平方向の両方に引き伸ばされるようにするにはどうすればよいですか?
画像を描画するためにアダプターを使用していることに注意してください。
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
imageView = new ImageView(context);
} else {
imageView = (ImageView) convertView;
}
imageView.setBackgroundResource(imageIds[position]);
return imageView;
}