1/ Create A add xml_main .
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ZoomControls_Task"
android:textSize="30dp"
android:gravity="center"
android:textStyle="bold"
android:textColor="#3F51B5"
android:layout_marginTop="0dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_marginTop="40dp"
android:layout_height="wrap_content"
android:text=""Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
android:textStyle="bold|italic"
android:textColor="@color/black"
android:background="#FF5722"
android:id="@+id/zoomin"
android:textSize="30sp"
android:gravity="center"/>
<ZoomControls
android:id="@+id/simpleZoomControl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginTop="20dp"
/></LinearLayout>
</RelativeLayout>
2/ /MainActivity.java file −
package com.example.userinput;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.ZoomControls;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class MainActivity extends AppCompatActivity {
private ZoomControls simpleZoomControls;
TextView img;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
simpleZoomControls = findViewById(R.id.simpleZoomControl);
img = findViewById(R.id.zoomin);
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((float) (x+0.1));
img.setScaleY((float) (x+0.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((float) (x-0.1));
img.setScaleY((float) (x-0.1));
}
});
}
}
OUTPUT