Introduction
In this article, we are going to see how to obtain Dismissible View in Android using Android Studio. Dismissible View is a famous library used widely throughout the world. They are used to provide the movable View to the given image and also render the animation.
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.
Check whether it is pasted correctly.
Step 3
Locate the Gradle Scripts >> Build. Gradle 1.
And, type the following dependency in your app's build.gradle.
Code copy is here.
- 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.
Code copy is here.
- compile 'com.github.dmallcott:DismissibleImageView:1.0.1'
Step 5
Next, go to app >> res >> layout >> activity_main.xml. Select activity page.
And, just type the code as follows.
Code copy is here.
- <com.dmallcott.dismissibleimageview.DismissibleImageView
- android:src="@drawable/a"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" />
Step 6
Next, go to app >> java>>Mainactivity.java. Select MainActivity page.
And check whether it is default or else make it default.
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 in our app and it is also used to define its width, height, and gravity.
Summary
We created a new app named Dismissible 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.