Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to show the full size image in popup on clicking the image in android

    • 0
    • 0
    • 0
    • 0
    • 2
    • 0
    • 0
    • 0
    • 12.1k
    Comment on it

    Below is the code that will show the full size image in a dialog box popup without defining layout xml file .

     

    In the code below I have taken two imageview named profile_pic and pro, to get the OnTouchListener action of particular image I have used the code

    int a=v.getId(); intiger "a" will have the value equal to profile_pic if we touched on profile_pic imageview else we will get pro id .

     

    Since I have copy pasted the images within my app drawable folder  so I am using the path as

    "uri = Uri.parse("android.resource://"+getPackageName()+"/drawable/pro");" If you are using the images on external storage then you have to give the path as   

    "uri = Uri.parse(path of your image);"


        
        

    private ImageView profile_pic,pro;
    
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_page);
    
         profile_pic=(ImageView)findViewById(R.id.img_View);
            pro=(ImageView)findViewById(R.id.go_pro);
            pro.setOnTouchListener(mTouchListener);
            profile_pic.setOnTouchListener(mTouchListener);    
    
        }
    
           private View.OnTouchListener mTouchListener=new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                Dialog builder = new Dialog(HomePage.this);
                builder.requestWindowFeature(Window.FEATURE_NO_TITLE);
                builder.getWindow().setBackgroundDrawable(
                        new ColorDrawable(android.graphics.Color.TRANSPARENT));
                builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialogInterface) {
                        //nothing;
                    }
                });
                int a=v.getId();
                if(R.id.go_pro==a)
                {
            uri = Uri.parse("android.resource://"+getPackageName()+"/drawable/pro");    //path of image
                }
                else if(R.id.img_View==a) {
          uri = Uri.parse("android.resource://" + getPackageName() + "/drawable/profile"); //path of image
                }
                ImageView imageView = new ImageView(HomePage.this);
                imageView.setImageURI(uri);                //set the image in dialog popup
    
                //below code fullfil the requirement of xml layout file for dialoge popup
           
    
         builder.addContentView(imageView, new RelativeLayout.LayoutParams(
                        ViewGroup.LayoutParams.WRAP_CONTENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT));
                builder.show();
    
                return false;
            }
        };

     

 2 Comment(s)

  • Thank you very much, this helped me a lot. I am making an app that uses images taken with a microscope camera, so I was wondering if there is a way to zoom in on the image, after the user makes it full screen? Thanks again, all the best. 
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: