Code Example

Kotlin Android Particle Animation Snippets

A step by step Android Particle Animation example.

1. ibrahimsn98/android-particles

A lightweight Particle Animation Library for Android.

Particle animation library for Android.

android-particles Example Tutorial

Example

android-particles Example Tutorial

Setup

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
dependencies {
      implementation 'com.github.ibrahimsn98:android-particles:2.0'
}

Attributions

<me.ibrahimsn.particle.ParticleView
    android:id="@+id/particleView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:particleCount="60"
    app:particleMinRadius="3"
    app:particleMaxRadius="10"
    app:particlesBackgroundColor="#23262a"
    app:particleColor="@android:color/holo_green_dark"
    app:particleLineColor="@android:color/holo_green_dark"
    app:particleLinesEnabled="true" />

Usage

class MainActivity : AppCompatActivity() {

    private lateinit var particleView: ParticleView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        particleView = findViewById(R.id.particleView)
    }

    override fun onResume() {
        super.onResume()
        particleView.resume()
    }

    override fun onPause() {
        super.onPause()
        particleView.pause()
    }
}

Full Example

Awaiting below is a full android sample to demonstrate the concept:

Step 1. Design Layouts

We need to design our XML layouts as follows:

(a). activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@android:color/black"
    tools:context=".MainActivity">

    <me.ibrahimsn.particle.ParticleView
        android:id="@+id/particleView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:particleCount="60"
        app:particleMinRadius="3"
        app:particleMaxRadius="10"
        app:particlesBackgroundColor="#23262a"
        app:particleColor="@android:color/holo_green_dark"
        app:particleLineColor="@android:color/holo_green_dark"
        app:particleLinesEnabled="true" />

</FrameLayout>

Step 2. Write Code

Finally we need to write our code as follows:

(a). MainActivity.kt

package me.ibrahimsn.particles

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import me.ibrahimsn.particle.ParticleView

class MainActivity : AppCompatActivity() {

    private lateinit var particleView: ParticleView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        particleView = findViewById(R.id.particleView)
    }

    override fun onResume() {
        super.onResume()
        particleView.resume()
    }

    override fun onPause() {
        super.onPause()
        particleView.pause()
    }
}

Reference

You can DOWNLOAD FULL CODE.
You can also browse code or read more here.
Follow code author here.


Read More.