Introduction
In this article, we are going to see how to create a Dot Loader in the Android app using the Android Studio. In a user interface, the Dot Loader plays a unique role. It is the only thing on a Splash page which will attract the user. We can define different levels of motions to the Dots.
Step 1
Create a new project in Android Studio.
Give a name to the project and click "Next".
Select "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
Set up the Gradle by just locating the Gradle Scripts>>Build.Gradle.
And type the following dependency in your app's build.gradle.
Code copy is given below.
- compile 'com.steelkiwi:dots-loader-view:1.0.0'
Step 3
Next, go to app >> res >> layout >> activity_main.xml. Select activity page.
And just type the code as given below.
The code copy is mentioned below.
- <steelkiwi.com.library.DotsLoaderView
- android:id="@+id/dotsLoader"
- android:visibility="visible"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- app:dlv_item_drawable="@drawable/circle_background"
- app:dlv_line_color="@color/point_color"
- />
Step 4
Next, go to app >> java>>Mainactivity.java. Select Mainactivity page.
And just type the code as given.
- DotsLoaderView dotsLoaderView;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
-
- dotsLoaderView = (DotsLoaderView)findViewById(R.id.dotsLoader);
-
- downloadDemo();
- }
-
- private void downloadDemo() {
- AsyncTask<String,String,String> demoAsync = new AsyncTask<String, String, String>() {
-
- @Override
- protected void onPreExecute() {
- dotsLoaderView.show();
- }
-
- @Override
- protected String doInBackground(String... params) {
- try {
- Thread.sleep(5000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- return "done";
- }
-
- @Override
- protected void onPostExecute(String s){
- if(s.equals("done"))
- dotsLoaderView.hide();
- }
- };
- demoAsync.execute();
Step 5
After step 4, sync all the dependency gradles and Mainactivity.java resource files by clicking the Sync button on the top right corner of the Gradle page.
Step 6
Verify the preview.
After the code is applied, the preview will appear like this.
Step 7
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 source code provided in this article is just the dependencies of motions and the code used in activity_main.xml will make the dots move and define its attributes.
Summary
In this article, we created the app named Dots Loader, then we have inserted a Gradle and we learned how to give motion to the dot and finally, we have deployed that as an output.
*Support and Share; Thank You*