Search code examples
androidimagetouch-eventwindow-managers

Android Gallery Image onTouch to fit screen


I am developing application having a resemblance appearance like " Gallery application". When I click on image from the gallery... I want to fit image to whole screen.. I used this code..but it does not work . can you guide me for this ... Here is code for the same:

  Display display = getWindowManager().getDefaultDisplay(); 
  int width = display.getWidth();
  int height = display.getHeight();

  imgView.setMinimumWidth(width);
  imgView.setMinimumHeight(height);

  imgView.setMaxWidth(width);
  imgView.setMaxHeight(height);

Solution

  • you should use the following attribute of the imageview to fit the image to the screen.

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

    Must be one of the following constant values.

    Constant Value

    matrix 0

    fitXY 1

    fitStart 2

    fitCenter 3

    fitEnd 4

    center 5

    centerCrop 6

    centerInside 7

    android:scaleType="fitxy"

    like wise you can use others to change the size of your image.