Skip to content
Alex Vasilkov edited this page Apr 4, 2017 · 9 revisions

Just add GestureImageView to your layout:

<com.alexvasilkov.gestures.views.GestureImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

Or add GestureFrameLayout:

<com.alexvasilkov.gestures.views.GestureFrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- GestureFrameLayout can contain only one child -->

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!-- Layout content goes here -->

    </FrameLayout>

</com.alexvasilkov.gestures.views.GestureFrameLayout>

Setup

GestureViews can be customised using gestureView.getController().getSettings():

gestureView.getController().getSettings()
        .setMaxZoom(2f)
        .setDoubleTapZoom(-1f) // Falls back to max zoom level
        .setPanEnabled(true)
        .setZoomEnabled(true)
        .setDoubleTapEnabled(true)
        .setRotationEnabled(false)
        .setRestrictRotation(false)
        .setOverscrollDistance(0f, 0f)
        .setOverzoomFactor(2f)
        .setFillViewport(false)
        .setFitMethod(Settings.Fit.INSIDE)
        .setGravity(Gravity.CENTER);

Note: example above shows default values, you will not need to set them yourself.

See also full settings list with descriptions.

ViewPager

If you plan to use GestureViews inside ViewPager you should additionally call:

gestureView.getController().enableScrollInViewPager(viewPager);

Listeners

You can listen for state changes (position, zoom, rotation):

addOnStateChangeListener(OnStateChangeListener listener)

removeOnStateChangeListener(OnStateChangeListener listener)

You can also listen for additional gestures:

  • onDown
  • onUpOrCancel
  • onSingleTapUp
  • onSingleTapConfirmed
  • onLongPress
  • onDoubleTap

with:

setOnGesturesListener(OnGestureListener listener)

Animations

See Basic animations and Advanced animations pages for more info.

Custom views

See Custom views page.

Image cropping

See Image cropping page.

Clone this wiki locally