Anderson
Anderson

Reputation: 111

Set imageView full screen on setOnClickListener

Simple: How to set imageView to full screen on setOnClickListener? Is this possible? If the answer is no, there is another method to do it? Thank you very much

Upvotes: 0

Views: 602

Answers (2)

Max Pinto
Max Pinto

Reputation: 1483

yes it is possible, try this: First declare a global after your Activity/Fragment definition

boolean isImageFitToScreen=false;

_imageView= (ImageView) findViewById(R.id.yourimageView);

        _imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(isImageFitToScreen) {
                    isImageFitToScreen=false;
                    imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
                    imageView.setAdjustViewBounds(true);
                }else{
                    isImageFitToScreen=true;
                    imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
                    imageView.setScaleType(ImageView.ScaleType.FIT_XY);
                }
            }
        });

That should Works.

Regards.

Upvotes: 0

EEJ
EEJ

Reputation: 678

The most basic way to do it using dialog.

  1. Create a dialog having image view as a layout.

  2. Set the dialog window feature to no title.

  3. Set the dialog theme to full screen using android style.

  4. Once click on image. Pass the image resouce reference to the dialog and open the dialog with same image.

Alternatively you can also seaech for some third party libraries and can use it. They might give some more feautered experience.

Upvotes: 2

Related Questions