TouchImageView Documentation

repository·master·Indexed 25 days ago

https://github.com/mikeortiz/touchimageview

An Android library that extends ImageView to provide advanced touch interactions including pinch zoom, dragging, flinging, and double-tap zoom. It includes methods for querying zoom and position information, programmatically controlling scale, and configuring fixed points for resizing and rotation.

Tokens
783
Snippets
1
Records
5
Agent score
33%

What's inside TouchImageView

  1. Install TouchImageView via JitPack

    master

    To use TouchImageView in your Android project, add the JitPack repository to your allprojects block and then add the dependency to your dependencies block. Use the SupportLib version for older projects or the AndroidX version for modern projects.

    allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }
    
    dependencies {
        // last SupportLib version
        implementation 'com.github.MikeOrtiz:TouchImageView:1.4.1' 
        
        // or for Android X
        implementation 'com.github.MikeOrtiz:TouchImageView:$LAST_VERSION' 
    }
  2. Get zoom and position information from TouchImageView

    master

    Use the following methods to query the current state of the TouchImageView:

    • getCurrentZoom(): Returns the current zoom relative to the initial scale.
    • getMaxZoom(): Returns the maximum zoom multiplier.
    • getMinZoom(): Returns the minimum zoom multiplier.
    • getScrollPosition(): Returns a PointF representing the center of the zoomed image. Coordinates are fractions between 0 and 1 (e.g., (0,0) is top-left, (1,1) is bottom-right).
    • getZoomedRect(): Returns a RectF representing the currently visible zoomed area.
    • isZoomed(): Returns true if the image is currently zoomed in, false if it is in the initial unzoomed state.
  3. Configure fixed points for resizing and rotation

    master

    To control which part of the image remains fixed during layout changes, use the following methods:

    • setViewSizeChangeFixedPixel(FixedPixel fixedPixel): Determines which part of the image remains fixed when the TouchImageView is resized.
    • setOrientationChangeFixedPixel(FixedPixel fixedPixel): Determines which part of the image remains fixed when the screen orientation changes.
  4. Control zoom and scale in TouchImageView

    master

    You can programmatically manipulate the zoom level and focus point of a TouchImageView using these methods:

    • resetZoom(): Resets zoom and translation to the initial state.
    • setMaxZoom(float max): Sets the maximum zoom multiplier (Default: 3).
    • setMinZoom(float min): Sets the minimum zoom multiplier (Default: 1). Use TouchImageView.AUTOMATIC_MIN_ZOOM to allow the user to see the whole image.
    • setMaxZoomRatio(float max): Sets the max zoom to stay at a fixed multiple of the min zoom multiplier.
    • setZoom(float scale): Sets zoom to the specified scale, centered by default.
    • setZoom(float scale, float focusX, float focusY): Sets zoom to the specified scale, centered around the provided focus point (fractions 0 to 1).
    • setZoom(float scale, float focusX, float focusY, ScaleType scaleType): Sets zoom to the specified scale and focus point using a specific ScaleType.
    • setZoom(TouchImageView img): Synchronizes the zoom parameters (scale, position, and ScaleType) with another TouchImageView instance.