Skip to content

07. Configuration

davemorrissey edited this page Nov 16, 2017 · 3 revisions

The view has various options for fine tuning its behaviour to make it suitable for a wide range of uses. If you don't see the option you need here, you can extend the class to add functionality, or fork the repository.

Please see javadocs for complete and up-to-date documentation.

setOrientation(int)

Set the orientation of the image in 90° increments, or use automatic rotation using EXIF data. Valid values:

  • ORIENTATION_USE_EXIF: Attempt to use the file's EXIF data to automatically rotate it. Supported for files only, not assets or resources.
  • ORIENTATION_0: Display image in its native orientation.
  • ORIENTATION_90: Rotate the image 90° clockwise.
  • ORIENTATION_180: Rotate the image 180°.
  • ORIENTATION_270: Rotate the image 270° clockwise.

See Displaying images.

setPanLimit(int)

Sets the limit for image panning. Regardless of this setting, the minimum scale is always calculated according to the width and height of the view and the minimum scale type setting. Valid values:

  • PAN_LIMIT_INSIDE: (Default) Panning stops when the image is inside the view and an edge reaches the edge of the screen. The image is centered in width or height if it doesn't fill that dimension.
  • PAN_LIMIT_CENTER: Panning stops when a corner of the image reaches the center of the screen. This can be useful if you want to allow any point of your image to be centered on screen.
  • PAN_LIMIT_OUTSIDE: The image can be panned until it is just off screen but no further.
setMinimumScaleType(int)

Defines how the minimum image scale should be calculated. Valid values:

  • SCALE_TYPE_CENTER_INSIDE: (Default) The standard for an image gallery. The whole image is visible at minimum scale, with both dimensions of the image equal to or less than the corresponding dimension of the view. The image is then centered in the view.
  • SCALE_TYPE_CENTER_CROP: Leaves no borders. Scales the image so that both dimensions of the image will be equal to or larger than the corresponding dimension of the view. The image is then centered in the view.
  • SCALE_TYPE_CUSTOM: Use together with setMinScale or setMaximumDpi to set a custom minimum scale.
setMinScale(float) / setMaximumDpi(int)

Sets the minimum scale allowed. setMinScale expresses this as a screen pixel to image pixel ratio so does not take into account the density of the screen. setMaximumDpi is density aware and usually the best method to use. These methods only work if you have called `setMinimumScaleType(SCALE_TYPE_CUSTOM). Note you can use padding to create a margin around the image when zoomed out.

setMaxScale(float) / setMinimumDpi(int)

Sets how far the image can be zoomed in. setMaxScale expresses this as a screen pixel to image pixel ratio so does not take into account the density of the screen. setMinimumDpi is density aware and usually the best method to use. The default is 160dpi - setting a lower minimum DPI will allow the image to be zoomed in further, when it will appear more blurry.

setDoubleTapZoomScale(float) / setDoubleTapZoomDpi(int)

Sets the scale the image should animate to when double tapped. setDoubleTapZoomScale expresses this as a screen pixel to image pixel ratio so does not take into account the density of the screen. setDoubleTapZoomDpi is density aware and usually the best method to use. The default is 160dpi (equal to the default max scale). Values higher than the max scale are ignored.

setDoubleTapZoomStyle(int)

Changes the behaviour of double tap zoom. Valid values:

  • ZOOM_FOCUS_FIXED: (Default) Animated zoom around the tapped point, leaving it in the same screen location.
  • ZOOM_FOCUS_CENTER: Animated zoom, panning the tapped point as close to the center of the screen as the panning limit allows.
  • ZOOM_FOCUS_CENTER_IMMEDIATE: Immediately zooms in, placing the tapped point as close to the center of the screen as the panning limit allows.
setDoubleTapZoomDuration(int)

Sets the duration of a double tap zoom animation, in milliseconds. The default is 500ms.

setPanEnabled(boolean)

Default true. Enables or disables pan gesture detection. Disabling pan causes the image to be centered. Animations and setScaleAndCenter can be used to pan the image from code.

setZoomEnabled(boolean)

Default true. Enables or disables zoom gesture detection, including quick scale. Disabling zoom locks the current scale. Animations and setScaleAndCenter can be used to zoom the image from code.

setQuickScaleEnabled(boolean)

Default true. Enables or disables quick scale gesture detection. Enabling this gesture is only effective if zoom is also enabled.

setTileBackgroundColor(int)

Default none. Renders a background color behind tiles. Useful when rendering a transparent PNG. *Note: transparent PNGs require double the memory of PNGs with no alpha layer, and may cause out of memory errors.

setRegionDecoderClass(Class), setBitmapDecoderClass(Class)

Allows use of custom region and full bitmap decoders. See Custom decoders

setDebug(boolean)

Default false. Toggles the display of debug information, including tile boundaries and loading state, translate and scale, and current sample size.