This page describes all the APIs related to zoom. These are common to all Zoom classes in the library, and also to the low level engine.
The transformation defines the engine resting position. It is a keyframe that is reached at
certain points, like at start-up or when explicitly requested through
The keyframe is defined by two elements:
transformationvalue (modifies zoom in a certain way)
transformationGravityvalue (modifies pan in a certain way)
which can be controlled through
setTransformation(int, int) or
||The content is scaled down or up so that it fits completely inside the view bounds.|
||The content is scaled down or up so that its smaller side fits exactly inside the view bounds. The larger side will be cropped.|
||No transformation is applied.|
After transformation is applied, the transformation gravity will reposition the content with
the specified value. Supported values are most of the
android.view.Gravity flags like
||The content is panned so that its top side matches teh container top side. Same for other values.|
||The transformation gravity is taken from the engine alignment, defaults to
Note: after transformation and gravity are applied, the engine will apply - as always - all the active constraints, including minZoom, maxZoom, alignment. This means that the final position might be slightly (or completely) different.
For example, when
maxZoom == 1, the content is forced to not be any larger than the container. This means that
centerCrop transformation will not have the desired effect: it will act just like a
You can force the content position with respect to the container using the
alignment XML flag of
The default value is
Alignment.CENTER which will center the content on both directions.
Note: alignment does not make sense when content is larger than the container, because forcing an alignment (e.g. left) would mean making part of the content unreachable (e.g. the right part).
||Force align the content to the same side of the container.|
||Force the content to be centered inside the container on that axis.|
||No alignment set: content is free to be moved on that axis.|
You can use the
or operation to mix the vertical and horizontal flags:
engine.setAlignment(Alignment.TOP or Alignment.LEFT) engine.setAlignment(Alignment.TOP) // Equals to Aligment.TOP or Alignment.NONE_HORIZONTAL engine.setAlignment(Alignment.NONE) // Remove any forced alignment
The base transformation makes the difference between zoom and realZoom. Since we have silently applied a base zoom to the content, we must introduce two separate types:
||The scale value after the initial transformation.
||The actual scale value, including the initial transformation.
To make things clearer, when transformation is
none, the zoom and the real zoom will be identical.
The distinction is very useful when it comes to imposing min and max constraints to our zoom value.
Note that these values will change if the
setContainerSize APIs are used
applyTransformation = true.
Some of the zoom APIs will let you pass an integer (either
to define the zoom type you are referencing to. Depending on the context, imposing restrictions on one type
will make more sense than the other - e. g., in a PDF viewer, you might want to cap real zoom at
||Returns the current zoom, not taking into account the base scale.||
||Returns the current zoom taking into account the base scale. This is the matrix scale.||
||Sets the lower bound when pinching out.||
||Sets the upper bound when pinching in.||
||If true, the content will be allowed to zoom outside its bounds, then return to its position.||
||Moves the real zoom to the given value, animating if needed.||
||Moves the zoom to the given value, animating if needed.||
||Applies the given factor to the current zoom, animating if needed. OK for both types.||
||Applies a small, animated zoom-in.||
||Applies a small, animated zoom-out.||
||If true, the content will be allowed to zoom in and out by user input.||
moveTo(float, float, float, boolean) API will let you animate both zoom and pan at the same time.