レイアウトについて
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="hogehoge" /> <ImageView android:layout_width="640dp" android:layout_height="360dp" android:id="@+id/image222" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="hogehoge2" />
hogehogeでImageViewを囲いました。
以下layout/drawable/test.pngを設置したところ表示されたので、layoutは問題ないと思いました。
ImageView iv = (ImageView) findViewById(R.id.image222); iv.setImageResource(R.drawable.test);
以下画像をpathで指定したときに画像が表示されません。
#1パターン目
https://stackoverflow.com/questions/15814638/how-to-set-an-image-to-imageview-using-filepath-in-android
を参考に以下を記述しました。
ImageView iv = (ImageView)findViewById(R.id.image222); String path = "/sdcard/test.png"; iv.setImageBitmap(BitmapFactory.decodeFile(path));
adb shellで端末内に画像があることは確認しました。
$ ls -ltA /sdcard/test.png -rw-rw---- 1 root sdcard_rw 522549 2019-01-15 15:48 /sdcard/test.png
表示したところhogehogeはでましたが、hogehogeに囲まれてる画像は出ませんでした。
#2パターン目
https://stackoverflow.com/questions/4181774/show-image-view-from-file-path
も参考に以下を記述しました。
ImageView iv = (ImageView)findViewById(R.id.image222); String path = "/sdcard/test.png"; File imgFile = new File(path); Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); iv.setImageBitmap(myBitmap);
が同様にhogehogeはでましたが、hogehogeに囲まれてる画像は出ませんでした。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。