Open In App

ParticleView in Android with Examples

Last Updated : 12 Sep, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

ParticleView is an animation library and animations help to gain the attention of the user so it is best to learn it. It is the custom android view that helps to display a large number of fairies.
particleview1

Why ParticleView?

  • ParticleView provides a predefined layout type and animation.
  • ParticleView can be used in Splash Screen.
  • It is better to use ParticleView because of its UI because a good UI plays a very important role in an app.

Approach

  • Step 1: Add the support library in the root build.gradle file (not in the module build.gradle file).

    allprojects {
    repositories {
    maven { url ‘https://dl.bintray.com/wangyuwei/maven’ }
    }
    }

  • Step 2: Add the support library in build.gradle file and add dependency in the dependencies section.

    implementation ‘me.wangyuwei:ParticleView:1.0.4’

  • Step 3: Add the following code in activity_main.xml file. In this file add the ParticleView to the layout.

    activity_main.xml




       
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        android:background="@color/grey"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:gravity="center">
      
        <me.wangyuwei.particleview.ParticleView
            android:id="@+id/particleView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            pv:pv_host_text="GeeksForGeeks"
            pv:pv_host_text_size="32sp"
            pv:pv_particle_text=".com"
            pv:pv_particle_text_size="18sp"
            pv:pv_text_color="@color/colorPrimary"
            pv:pv_background_color="#FFF"
            pv:pv_text_anim_time="2000"
            pv:pv_spread_anim_time="300"
            pv:pv_host_text_anim_time="1000" />
      
    </LinearLayout>

    
    

  • Step 4: Add the following code in MainActivity.java file. In this file add ParticleAnimationListner() which will get invoked automatically when animation ends.

    MainActivity.java




    package org.geeksforgeeks.particleView          
      
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Toast;
    import androidx.annotation.Nullable;
    import androidx.appcompat.app.AppCompatActivity;
    import me.wangyuwei.particleview.ParticleView;
      
    public class MainActivity extends AppCompatActivity {
      
        ParticleView particleView;
        @Override
        protected void onCreate(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
      
            particleView = findViewById(R.id.particleView);
            particleView.startAnim();
      
            // this listner will get invoked automatically
            // when animaion ends.
            particleView.setOnParticleAnimListener(
                    new ParticleView.ParticleAnimListener() {
                @Override
                public void onAnimationEnd() {
                    Toast.makeText(MainActivity.this,
                            "Animation is End!!"
                             Toast.LENGTH_SHORT).show();
                }
            });
        }
    }

    
    

Similar Reads