facebook twitter hatena line email

Android/画像/画像表示

提供: 初心者エンジニアの簡易メモ
2019年1月16日 (水) 10:29時点におけるAdmin (トーク | 投稿記録)による版

移動: 案内検索

以下に画像を設置

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()より下に記述してるかどうか。