How to show imageView full screen on imageView click? How to show imageView full screen on imageView click? android android

How to show imageView full screen on imageView click?


You can use ImageView below two properties to show image based on your requirement :

  1. android:adjustViewBounds : Set this to true if you want the ImageView to adjust its bounds to preserve the aspect ratio of its drawable.

  2. android:scaleType :Controls how the image should be resized or moved to match the size of this ImageView

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

Above two properties can be use either xml or java code.

As you need to decide at run time need to show image into full screen or not so will apply above two properties at java code as below :

public class MainActivity extends Activity {    ImageView imageView;    boolean isImageFitToScreen;    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        imageView = (ImageView) findViewById(R.id.imageView);        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);                }            }        });    }}


Use Immersive Full-Screen Mode

enter image description here

call fullScreen() on ImageView click.

 public void fullScreen() {        // BEGIN_INCLUDE (get_current_ui_flags)        // The UI options currently enabled are represented by a bitfield.        // getSystemUiVisibility() gives us that bitfield.        int uiOptions = getWindow().getDecorView().getSystemUiVisibility();        int newUiOptions = uiOptions;        // END_INCLUDE (get_current_ui_flags)        // BEGIN_INCLUDE (toggle_ui_flags)        boolean isImmersiveModeEnabled =                ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions);        if (isImmersiveModeEnabled) {            Log.i(TAG, "Turning immersive mode mode off. ");        } else {            Log.i(TAG, "Turning immersive mode mode on.");        }        // Navigation bar hiding:  Backwards compatible to ICS.        if (Build.VERSION.SDK_INT >= 14) {            newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;        }        // Status bar hiding: Backwards compatible to Jellybean        if (Build.VERSION.SDK_INT >= 16) {            newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN;        }        // Immersive mode: Backward compatible to KitKat.        // Note that this flag doesn't do anything by itself, it only augments the behavior        // of HIDE_NAVIGATION and FLAG_FULLSCREEN.  For the purposes of this sample        // all three flags are being toggled together.        // Note that there are two immersive mode UI flags, one of which is referred to as "sticky".        // Sticky immersive mode differs in that it makes the navigation and status bars        // semi-transparent, and the UI flag does not get cleared when the user interacts with        // the screen.        if (Build.VERSION.SDK_INT >= 18) {            newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;        }        getWindow().getDecorView().setSystemUiVisibility(newUiOptions);        //END_INCLUDE (set_ui_flags)    }

Read more

Example Download


use following property of ImageView for full size of image

 android:scaleType="fitXY"

ex :

      <ImageView        android:id="@+id/tVHeader2"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:scaleType="fitXY"        android:gravity="center"        android:src="@drawable/done_sunheading" />

1)Switch on other activity when click on image.

2)pass url in intent

3)Take imageview on that Activity and set above property of imageview

4)Get the url from intent and set that image.

but using this your image may be starched if it will of small size.