ImageView not refreshing/reflecting changes

前端 未结 8 1154
星月不相逢
星月不相逢 2021-01-03 22:26

I\'m using a photo picker intent to choose an image and write it to an application-private file. Most of my important source code is shown below. Once I press a button and p

相关标签:
8条回答
  • 2021-01-03 22:42

    ImageView will not redraw if "new" URI is the same like old one. "View.invalidate()" will not work. To "force" update you can do:

    public void onResume() {
      super.onResume();
      ImageView myImageView = (ImageView)findViewById(R.id.contact_image);
      if (hasImage) {
        myImageView.setImageDrawable(null); // <--- added to force redraw of ImageView
        myImageView.setImageURI(Uri.fromFile(getFileStreamPath(TEMP_PHOTO_FILE)));
      }
    }
    
    0 讨论(0)
  • 2021-01-03 22:47

    I had a similar problem where I was using the devices camera to take a picture and then wanting the imageView in the original screen to refresh when I returned to it. The solution was to call View.invalidate() in onResume().

    0 讨论(0)
  • 2021-01-03 22:53

    I would suggest this thing solution. After trying lot of solutions i found this one worked for me.

    final Handler handler = new Handler();
                        handler.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                //Do something after 1000ms
                                ivProfilePic.setImageBitmap(bitImage);
    
                            }
                        }, 1000);
    
    0 讨论(0)
  • 2021-01-03 22:54

    invalidate() not worked. Try hack :

        imageView.setImageURI(null);
        imageView.setImageURI(newUri);
    
    0 讨论(0)
  • 2021-01-03 22:57

    To force redrawing your widget/View just call View.invalidate();

    0 讨论(0)
  • 2021-01-03 22:57
            UIView.transition(with: bannerImageView, duration: 0.3, options: [.transitionCrossDissolve], animations: { [weak self] in
                self?.exampleImageView.image = newImage
            })
    

    Use this func in your view controller

    0 讨论(0)
提交回复
热议问题