「Android/画像/画像表示」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→画像をフィットさせる) |
|||
| (同じ利用者による、間の3版が非表示) | |||
| 行18: | 行18: | ||
MainActivity.java | MainActivity.java | ||
| − | ImageView | + | 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_START); | ||
| + | |||
| + | 参考:https://akira-watson.com/android/imageview_scaletype.html | ||
2019年3月11日 (月) 15:42時点における最新版
以下に画像を設置
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_START);
参考:https://akira-watson.com/android/imageview_scaletype.html
