Introduction
In this article, we are going to see how to obtain Zoom View in Android using Android Studio. Zooming view is a famous library used widely through over the world used to provide a zoomed view of a given image.
Step 1
Create a new project in Android Studio.
Give a name to the project and click "Next".
Select the "Phone and Tablet" and click "Next".
Select an empty activity and click "Next".
At last, give the activity name and click on "Finish".
Step 2
Next, copy the image in .png format
Locate app>>res>>drawable folder and paste the copied image into the drawable folder.
Step 3
Locate the Gradle Scripts>>Build. Gradle 1
And type the following dependency in your app's build.gradle.
Code copy is here,
- repositories {
- maven { url "https://jitpack.io" }
- }
Step 4
Locate the Gradle Scripts>>Build. Gradle 2
And type the following dependency in your app's build.gradle.
The code copy is here.
- dependencies {
- implementation 'com.github.chrisbanes:2.1.3'
- }
Step 5
Next, go to app >> res >> layout >> activity_main.xml. Select activity page.
And, just type the code as follows.
The code copy is here.
- <com.github.chrisbanes.photoview.PhotoView
- android:id="@+id/photo_view"
- android:layout_width="match_parent"
- android:layout_height="match_parent"/>
Step 6
Next, go to app >> java>>Mainactivity.java. Select Mainactivity page.
And check whether it is default or else make it default.
The code copy is here.
- PhotoView photoView = (PhotoView) findViewById(R.id.photo_view);
- photoView.setImageResource(R.drawable.developer);
Step 7
Verify the preview.
->After the code is applied, the preview will appear like this.
Step 8
Next, go to Android Studio and deploy the application. Select an Emulator or your Android mobile with USB debugging enabled. Give it a few seconds to make installations and set permissions.
Run the application in your desired emulator (Shift + F10).
Explanation of source code
The code used in the activity_main.xml is used to insert the image into our app and it is also used to define its width, height, and gravity.
Summary
We created a new app named zoom view and placed the image in the drawable folder. After that, we have inserted the Gradle dependencies to build Gradle and verified the deployed output.