How to show imageView full screen on imageView click?

后端 未结 10 637
暖寄归人
暖寄归人 2020-12-02 08:41

I am getting images from url and showing it on the imageView. This functionality is working properly. But I want that when I click on that image, then it must be full screen

10条回答
  •  庸人自扰
    2020-12-02 09:07

    It's easy to achieve this is to just use an Intent like this: (I put the method in a custom class that takes in an Activity as a parameter so it can be called from any Fragment or Activity)

        public class UIutils {
    
    private Activity mActivity;
    
        public UIutils(Activity activity){
            mActivity = activity;
        }
    
    public void showPhoto(Uri photoUri){
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.setDataAndType(photoUri, "image/*");
            mActivity.startActivity(intent);
        }
    }
    

    Then to use it just do this:

    imageView.setOnClickListener(v1 -> new UIutils(getActivity()).showPhoto(Uri.parse(imageURI)));
    

    I use this with an Image URL but it can be used with stored files as well. If you are accessing images form the phones memory you should use a content provider.

提交回复
热议问题