How to show image using ImageView in Android

前端 未结 5 1533
故里飘歌
故里飘歌 2020-12-08 04:27

I am looking for the way to assign image src to image view control. I read few example and they says something src=\"@drawable\\image\" but didn\'t understand t

5条回答
  •  没有蜡笔的小新
    2020-12-08 05:14

    You can set imageview in XML file like this :

    
    

    and you can define image view in android java file like :

    ImageView imageView = (ImageView) findViewById(R.id.imageViewId);
    

    and set Image with drawable like :

    imageView.setImageResource(R.drawable.imageFileId);
    

    and set image with your memory folder like :

    File file = new File(SupportedClass.getString("pbg"));
    if (file.exists()) {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inPreferredConfig = Bitmap.Config.ARGB_8888;
            Bitmap selectDrawable = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
            imageView.setImageBitmap(selectDrawable);
    }
    else
    {
          Toast.makeText(getApplicationContext(), "File not Exist", Toast.LENGTH_SHORT).show();
    }
    

提交回复
热议问题