1/ Create A New Project and design the page
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/tutorialb" />
<ZoomControls
android:id="@+id/simpleZoomControl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/img"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp" />
</RelativeLayout>
2/ Java Activity
package com.tutorialb.pagezoom;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ZoomControls;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private ZoomControls simpleZoomControls;
ImageView img;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
simpleZoomControls = findViewById(R.id.simpleZoomControl);
img = findViewById(R.id.img);
simpleZoomControls.setOnZoomInClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Add your zoom in functionality here
float x= img.getScaleX();
float y = img.getScaleY();
img.setScaleX(x+1);
img.setScaleY(x+1);
}
});
simpleZoomControls.setOnZoomOutClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Add your zoom out functionality here
float x= img.getScaleX();
float y = img.getScaleY();
img.setScaleX(x-1);
img.setScaleY(x-1);
}
});
}
}
3/ Ran And Output