How to Zoom-In and Zoom-Out on Imageview in Android using Zoomage

In this android programming code example, we are going the explore how to pinch ImageView to zoom-in and zoom-out in android.

Steps

  1. Add this line of code in your project build.gradle implementation 'com.jsibbold:zoomage:1.2.0'to have access to Zoomage library classes, interface and methods in your project.
  2. Add a custom ZoomageView in XML layout file
  3. Get the instance of the ZoomageView in the Activity class.
  4. You can use some of the ZoomageView attributes depending on your use-case.

build.gradle

implementation 'com.jsibbold:zoomage:1.2.0'

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.jsibbold.zoomage.ZoomageView
        android:id="@+id/myZoomageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/camera"
        app:zoomage_restrictBounds="false"
        app:zoomage_animateOnReset="true"
        app:zoomage_autoResetMode="UNDER"
        app:zoomage_autoCenter="true"
        app:zoomage_zoomable="true"
        app:zoomage_translatable="true"
        app:zoomage_minScale="0.6"
        app:zoomage_maxScale="8" />

</RelativeLayout>

MainActivity.java

import android.os.Bundle;

import com.jsibbold.zoomage.ZoomageView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = MainActivity.class.getSimpleName();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ZoomageView imageZoom = (ZoomageView)findViewById(R.id.myZoomageView);

    }
}

android zoom imageview

If you have any questions or suggestions kindly use the comment box or you can contact us directly through our contact page below.

 

Add a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

50% Discounts On Projects

Do you have a custom project with a clear requirements, we are currently giving a 50% discount on all projects.

We will work with you to ensure we deliver what you need.

If you have questions or want to chat with us, you can reach us on Skype (henry.tochi)

Languages and technologies we use - Java, Kotlin, Laravel, Vue, React, Flutter, Swift and more.