「Android/画像/画像表示」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→画像表示が出ない場合) |
|||
| 行25: | 行25: | ||
==画像をフィットさせる== | ==画像をフィットさせる== | ||
| + | <ImageView | ||
| + | android:id="@+id/image1" | ||
| + | android:scaleType=”fitCenter” | ||
| + | android:layout_width="match_parent" | ||
| + | android:layout_height="match_parent" /> | ||
| − | |||
| − | |||
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER); | imageView.setScaleType(ImageView.ScaleType.FIT_CENTER); | ||
参考:https://akira-watson.com/android/imageview_scaletype.html | 参考:https://akira-watson.com/android/imageview_scaletype.html | ||
2019年3月11日 (月) 15:41時点における版
以下に画像を設置
res/drawable/test.png
res/layout/activity_main.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="view start" />
<ImageView
android:id="@+id/image1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="view end" />
MainActivity.java
ImageView iv = (ImageView) findViewById(R.id.image1); iv.setImageResource(R.drawable.test);
画像表示が出ない場合
setContentView()より下に記述してるかどうか。
画像をフィットさせる
<ImageView
android:id="@+id/image1"
android:scaleType=”fitCenter”
android:layout_width="match_parent"
android:layout_height="match_parent" />
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
参考:https://akira-watson.com/android/imageview_scaletype.html
