How to see image in full screen when clicking on it?

0

Good morning.

I have an image in my layout, by clicking on it it should be shown in full screen. How could I do it? Thank you in advance.

here the activity

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_upload);

    ImageView image = (ImageView)findViewById(R.id.imgShow);

    Picasso.with(this).load("https://upload.wikimedia.org/wikipedia/en/1/19/Optimus10108pieces.jpg").into(image);

}

here the xml     

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imgShow"
    android:layout_below="@+id/btn_upload"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="59dp" />

    
asked by devjav 13.01.2017 в 17:05
source

1 answer

2

It could be done this way:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center">

    <ImageView
        android:id="@+id/imgShow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:src="@drawable/ic_tu_imagen"/>

</RelativeLayout>

ActivityUpload.java

public class ActivityUpload extends Activity {

    ImageView imageView;

    boolean isImageFitToScreen;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_upload);

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

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

    }
}
    
answered by 13.01.2017 в 17:36