Jetpack Compose Loading Animation 1 (with Source Code)

Jetpack Compose Loading Animation

This is a Jetpack Compose loading animation. It consists of a circle with a border. The circle is made with the Box layout. Its border is set with Modifier.border() method. The border’s alpha value and the circle’s scale is animated. The source code is available for free below.

The animation utilizes several Jetpack Compose APIs like animateFloatAsState, infiniteRepeatable, tween, etc. The circleScale variable is used to manage the state of the circle’s scale value. Initially, its value is 0f. When the app is launched, its value will be changed to 1f. The circleScaleAnimate is for animating the box. It is an infinite animation. It lasts forever.

The Jetpack Compose loading animation takes 2 arguments – circleColor and animationDelay. The circleColor is for the box’s border and animationDelay is the animation duration. You can change them according to your requirements.

I’m using the infiniteRepeatable to create the infinite animation. It takes animation spec. I’m passing the tween method. It accepts durationMillis which is the animation duration. The circle that actually gets animated is made with the Box layout. Its scale and alpha (opacity) values are updated every single frame.

Before using the code, make sure that you are using the latest Android Studio. Jetpack Compose doesn’t work in the older versions.

Final Output:

If the video isn’t working, watch it on the YouTube.

Helpful Links to Understand the Code:

Resources Used in the Project:

Here are the Gradle files used in the project.

Jetpack Compose Loading Animation Source Code:


import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.core.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.scale
import androidx.compose.ui.unit.dp

You can use the following code for commercial purposes with some restrictions.
Read the full license here:
For more designs with source code, visit:
class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        setContent {
            YourProjectNameTheme(darkTheme = false) {
                    modifier = Modifier.fillMaxSize(),
                    verticalArrangement = Arrangement.Center,
                    horizontalAlignment = Alignment.CenterHorizontally
                ) {

fun LoadingAnimation1(
    circleColor: Color = Color.Magenta,
    animationDelay: Int = 1000
) {

    // circle's scale state
    var circleScale by remember {

    // animation
    val circleScaleAnimate = animateFloatAsState(
        targetValue = circleScale,
        animationSpec = infiniteRepeatable(
            animation = tween(
                durationMillis = animationDelay

    // This is called when the app is launched
    LaunchedEffect(Unit) {
        circleScale = 1f

    // animating circle
        modifier = Modifier
            .size(size = 64.dp)
            .scale(scale = circleScaleAnimate.value)
                width = 4.dp,
                color = circleColor.copy(alpha = 1 - circleScaleAnimate.value),
                shape = CircleShape
    ) {



Leave a Comment