我有一个带有 xml 中设置图像的 imageView。但是,当我尝试更改图像时,ImageView 永远不会显示第二张图像。相反,它显示一个空白屏幕。我已经尝试了使用和不使用 invalidate() 的代码,并且没有任何变化。
ImageView image;
String imgPath=Environment.getExternalStorageDirectory()+"/Music/Evanescence - Discography - 1998-2011 (320 kbps)/Album's/2000 Origin (Limited Edition) (320 kbps)/Scans covers/06.jpg";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image=(ImageView)findViewById(R.id.imageView1);
image.setImageBitmap(BitmapFactory.decodeFile(imgPath));
if(!new File(imgPath).exists())
Log.i("aaa","File doesnt exist");
//select image from gallery
//Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
//photoPickerIntent.setType("image/*");
//startActivityForResult(photoPickerIntent, SELECT_PHOTO);
Log.i("aaa","DONE. img path: "+imgPath);
}