The Wayback Machine - https://web.archive.org/web/20240927083507/https://www.geeksforgeeks.org/circular-reveal-animation-in-android/
Open In App

Circular Reveal Animation in Android

Last Updated : 02 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Animations in Android play an important role in the user experience. This makes the user focus on the main content, which they want. And also helps in user interactivity. Animations communicate with the user to really get engaged in application usage. So in this article, one of the animations in android which is the most popular one, Circular reveal animation is discussed. Have a look at the following image to get an idea of how the circular animation looks like. Note that we are going to implement this project using the Kotlin language. 

Steps to Implement the Circular Animation in Android

Step 1: Create an empty activity project

Step 2: Working with the activity_main.xml file

  • To implement the application’s main layout in which includes only a single button, which when clicked on it triggers the Circular reveal animation.
  • To implement the UI invoke the following code inside the activity_main.xml file.


We can check them using Animations:

1. Circular Animation from the Bottom

bottom

2. Circular Animation from Center

circular


XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/mainLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity"
    tools:ignore="HardcodedText">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:gravity="center"
        android:text="GeeksforGeeks"
        android:textColor="@color/green_500"
        android:textSize="24sp"
        android:textStyle="bold" />

    <!--The layout which is invisible initially-->
    <LinearLayout
        android:id="@+id/revealLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/green_200"
        android:gravity="center"
        android:orientation="vertical"
        android:visibility="gone">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:backgroundTint="@android:color/white"
            android:text="LEARN PROGRAMMING"
            android:textColor="@android:color/black" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:backgroundTint="@android:color/white"
            android:text="CONTRIBUTE"
            android:textColor="@android:color/black" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:backgroundTint="@android:color/white"
            android:text="VISIT WEBSITE"
            android:textColor="@android:color/black" />

    </LinearLayout>

    <!--The Fab to toggle the visibility of circular reveal animation-->
    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentBottom="true"
        android:layout_gravity="bottom|end"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="16dp"
        app:srcCompat="@drawable/ic_add" />

</RelativeLayout>

Output UI:

GFGframepixel2

UI


Now revealing the same layout from the bottom of the screen

Step 3: Working with the MainActivity.kt file

  • Firstly, the code is for the circular reveal animation from the right bottom of the screen.
  • Invoke the following code and refer to its output for better understanding, the comments are added for better understanding.
Kotlin
import android.animation.Animator
import android.annotation.SuppressLint
import android.content.res.ColorStateList
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.ViewAnimationUtils
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.res.ResourcesCompat
import com.google.android.material.floatingactionbutton.FloatingActionButton
import kotlin.math.hypot
import kotlin.math.max

class MainActivity : AppCompatActivity() {

    private lateinit var mRevealLayout: View
    private lateinit var mFab: FloatingActionButton

    // boolean variable to check whether the
      // reveal layout is visible or not
    private var isRevealed = false

    @RequiresApi(Build.VERSION_CODES.M)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        mRevealLayout = findViewById(R.id.revealLayout)
        mFab = findViewById(R.id.fab)

        // initially the color of the FAB should be green
        mFab.backgroundTintList = ColorStateList.valueOf(
                ResourcesCompat.getColor(
                        resources,
                        R.color.green_500,
                        null
                )
        )

        // upon clicking the FAB the reveal should be 
          // toggled according to the boolean value
        mFab.setOnClickListener {
            revealLayoutFun()
        }
    }

    // this function is triggered when 
      // the FAB is clicked
    @RequiresApi(Build.VERSION_CODES.M)
    @SuppressLint("ResourceAsColor")
    private fun revealLayoutFun() {

        // based on the boolean value the 
          // reveal layout should be toggled
        if (!isRevealed) {

            // get the right and bottom side 
              // lengths of the reveal layout
            val x: Int = mRevealLayout.right
            val y: Int = mRevealLayout.bottom

            // here the starting radius of the reveal 
              // layout is 0 when it is not visible
            val startRadius = 0

            // make the end radius should match
              // the while parent view
            val endRadius = hypot(
                    mRevealLayout.width.toDouble(),
                    mRevealLayout.height.toDouble()
            ).toInt()

            // and set the background tint of the FAB to white 
              // color so that it can be visible
            mFab.backgroundTintList = ColorStateList.valueOf(
                    ResourcesCompat.getColor(
                            resources,
                            R.color.white,
                            null
                    )
            )
            // now set the icon as close for the FAB
            mFab.setImageResource(R.drawable.ic_close)

            // create the instance of the ViewAnimationUtils to 
              // initiate the circular reveal animation
            val anim = ViewAnimationUtils.createCircularReveal(
                    mRevealLayout,
                    x,
                    y,
                    startRadius.toFloat(),
                    endRadius.toFloat()
            )

            // make the invisible reveal layout to visible 
              // so that upon revealing it can be visible to user
            mRevealLayout.visibility = View.VISIBLE
            // now start the reveal animation
            anim.start()

            // set the boolean value to true as the reveal
              // layout is visible to the user
            isRevealed = true

        } else {

            // get the right and bottom side lengths 
              // of the reveal layout
            val x: Int = mRevealLayout.right
            val y: Int = mRevealLayout.bottom

            // here the starting radius of the reveal layout is its full width
            val startRadius: Int = max(mRevealLayout.width, mRevealLayout.height)

            // and the end radius should be zero 
              // at this point because the layout should be closed
            val endRadius = 0

            // now set the background tint of the FAB to green
              // so that it can be visible to the user
            mFab.backgroundTintList = ColorStateList.valueOf(
                    ResourcesCompat.getColor(
                            resources,
                            R.color.green_500,
                            null
                    )
            )

            // now again set the icon of the FAB to plus
            mFab.setImageResource(R.drawable.ic_add)

            // create the instance of the ViewAnimationUtils to 
              // initiate the circular reveal animation
            val anim = ViewAnimationUtils.createCircularReveal(
                    mRevealLayout,
                    x,
                    y,
                    startRadius.toFloat(),
                    endRadius.toFloat()
            )

            // now as soon as the animation is ending, the reveal 
              // layout should also be closed
            anim.addListener(object : Animator.AnimatorListener {
                override fun onAnimationStart(animator: Animator) {}
                override fun onAnimationEnd(animator: Animator) {
                    mRevealLayout.visibility = View.GONE
                }

                override fun onAnimationCancel(animator: Animator) {}
                override fun onAnimationRepeat(animator: Animator) {}
            })

            // start the closing animation
            anim.start()

            // set the boolean variable to false
              // as the reveal layout is invisible
            isRevealed = false
        }
    }
}

Output:

Now revealing the same layout from the center of the screen

Note: The layout of the application remains same only the code from the MainActivity.kt file are changed.

  • Invoke the following code inside the MainActivity.kt file to reveal the same layout from the center of the screen.
Kotlin
import android.animation.Animator
import android.annotation.SuppressLint
import android.content.res.ColorStateList
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.ViewAnimationUtils
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.res.ResourcesCompat
import com.google.android.material.floatingactionbutton.FloatingActionButton
import kotlin.math.hypot
import kotlin.math.max

class MainActivity : AppCompatActivity() {

    private lateinit var mRevealLayout: View
    private lateinit var mFab: FloatingActionButton

    // boolean variable to check whether
      // the reveal layout is visible or not
    private var isRevealed = false

    @RequiresApi(Build.VERSION_CODES.M)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        mRevealLayout = findViewById(R.id.revealLayout)
        mFab = findViewById(R.id.fab)

        // initially the color of the FAB should be green
        mFab.backgroundTintList = ColorStateList.valueOf(
                ResourcesCompat.getColor(
                        resources,
                        R.color.green_500,
                        null
                )
        )

        // upon clicking the FAB the reveal should
          // be toggled according to the boolean value
        mFab.setOnClickListener {
            revealLayoutFun()
        }
    }

    // this function is triggered when
      // the FAB is clicked
    @RequiresApi(Build.VERSION_CODES.M)
    @SuppressLint("ResourceAsColor")
    private fun revealLayoutFun() {

        // based on the boolean value the 
          // reveal layout should be toggled
        if (!isRevealed) {

            // get the right and bottom side 
              // lengths of the reveal layout
            val x: Int = mRevealLayout.right / 2
            val y: Int = mRevealLayout.bottom / 2

            // here the starting radius of the reveal
              // layout is 0 when it is not visible
            val startRadius = 0

            // make the end radius should
              // match the while parent view
            val endRadius = hypot(
                    mRevealLayout.width.toDouble(),
                    mRevealLayout.height.toDouble()
            ).toInt()

            // and set the background tint of the FAB to white 
             // color so that it can be visible
            mFab.backgroundTintList = ColorStateList.valueOf(
                    ResourcesCompat.getColor(
                            resources,
                            R.color.white,
                            null
                    )
            )
            // now set the icon as close for the FAB
            mFab.setImageResource(R.drawable.ic_close)

            // create the instance of the ViewAnimationUtils to 
              // initiate the circular reveal animation
            val anim = ViewAnimationUtils.createCircularReveal(
                    mRevealLayout,
                    x,
                    y,
                    startRadius.toFloat(),
                    endRadius.toFloat()
            )

            // make the invisible reveal layout to visible 
              // so that upon revealing it can be visible to user
            mRevealLayout.visibility = View.VISIBLE
            // now start the reveal animation
            anim.start()

            // set the boolean value to true as the reveal 
              // layout is visible to the user
            isRevealed = true

        } else {

            // get the right and bottom side lengths
              // of the reveal layout
            val x: Int = mRevealLayout.right / 2
            val y: Int = mRevealLayout.bottom / 2

            // here the starting radius of the reveal layout is its full width
            val startRadius: Int = max(mRevealLayout.width, mRevealLayout.height)

            // and the end radius should be zero at this 
              // point because the layout should be closed
            val endRadius = 0

            // now set the background tint of the FAB to green
              // so that it can be visible to the user
            mFab.backgroundTintList = ColorStateList.valueOf(
                    ResourcesCompat.getColor(
                            resources,
                            R.color.green_500,
                            null
                    )
            )

            // now again set the icon of the FAB to plus
            mFab.setImageResource(R.drawable.ic_add)

            // create the instance of the ViewAnimationUtils 
              // to initiate the circular reveal animation
            val anim = ViewAnimationUtils.createCircularReveal(
                    mRevealLayout,
                    x,
                    y,
                    startRadius.toFloat(),
                    endRadius.toFloat()
            )

            // now as soon as the animation is ending, the reveal 
              // layout should also be closed
            anim.addListener(object : Animator.AnimatorListener {
                override fun onAnimationStart(animator: Animator) {}
                override fun onAnimationEnd(animator: Animator) {
                    mRevealLayout.visibility = View.GONE
                }

                override fun onAnimationCancel(animator: Animator) {}
                override fun onAnimationRepeat(animator: Animator) {}
            })

            // start the closing animation
            anim.start()

            // set the boolean variable to false 
             // as the reveal layout is invisible
            isRevealed = false
        }
    }
}

Output:



Similar Reads

Star Shower in Android using Android Property Animation
In this article, we are going to create a star shower using android property animation. We will create a slightly more involved animation, animating multiple properties on multiple objects. For this effect, a button click will result in the creation of a star with a random size, which will be added to the background container, just out of view of t
7 min read
Android Animation using Android Studio
In today's world which is filled with full of imagination and visualizations, there are some areas that are covered with the word animation. When this word will come to anyone’s mind they always create a picture of cartoons and some Disney world shows. As we already know that among kids, animation movies are very popular like Disney world, Doraemon
5 min read
How to Add Fade and Shrink Animation in RecyclerView in Android?
In this article, we are going to show the fade and shrink animation in RecyclerView. When we move downward then the item at the top will be fading out and then it will shrink. In the output, we can see how it is happening. We will be implementing this Java programming language. [video mp4="https://media.geeksforgeeks.org/wp-content/uploads/20210403
3 min read
How to add TextSwitcher with animation in Android using Java
A TextSwitcher is used to animate a text on a screen. It is the child class of the ViewSwitcher class. It contains only one child of type TextView. In order to set animation on TextSwitcher we have to add animation tag or we can add programmatically. Here are the some usage of TextSwitcher: Changing numbers in a Date Picker Countdown of timer clock
2 min read
Create Floating Animation for RecyclerView Items in Android
In Android, a RecyclerView is a UI element that is used to display a type of layout items in the form of a list. This list is scrollable and each element of the list is clickable. You can find more information on creating RecyclerView in this article: RecyclerView in Android with Example. RecyclerView by default has no entry or exit animation. Howe
5 min read
How to make Heart Fill animation in Android
AnimatedVectorDrawable class was introduced in API 21 and is used to animate Vector Drawables beautifully and easily. Using AnimatedVectorDrawable, one can: Rotate, Scale, Translate VectorDrawables Animate the VectorDrawable such as fill color etc. Draw paths and do Path Morphing An AnimatedVectorDrawable element has a VectorDrawable attribute, and
4 min read
How to add fading TextView animation in Android
TextView is the basic building block of user interface components. It is used to set the text and display it to the user. It is a very basic component and used a lot. A Fading TextView is a TextView that changes its content automatically every few seconds. If we want to design a beautiful interface than we can use Fading TextView. Approach: Add thi
1 min read
How to add Lottie Animation in an Android app
This article is about enhancing the User Interface of the mobile application by adding Lottie animation files into our mobile app. The Lottie animations are free to use vector animation files. These animation files can be found at the official site here. Many famous applications use this such as Uber, Netflix, Google, Airbnb, Shopify, etc.Below is
2 min read
Create an Instagram/Twitter Heart Like Animation in Android
In this article, let's learn how to create an Instagram/Twitter heart Like animation in android. Twitter's Like animation is quite good and attractive. Suppose one wants to make an app like Twitter, Instagram, or Facebook where users can like posts there one can use this view. One can also use Leonids instead of this but it is very easy to use as c
3 min read
Bounce Animation in Android
To make the android app more attractive we add many things and animation is one of the best things which makes the app more attractive and engages the user with the app. So in this article, we will add a bounce animation to the Button. One can use this tutorial to add Bounce animation to any View in android studio such as ImageView, TextView, EditT
3 min read
How to Create Anim Folder & Animation File in Android Studio?
The animation is a method in which a collection of images is combined in a specific way and processed then they appear as moving images. Building animations make on-screen objects seem to be alive. To apply Animations to the Application sometimes we need to make an anim folder in Android Studio to store the animation file under the resource folder
2 min read
How to Add CrossFade Animation Between Activities in Android?
Android animations are the object which can be said the most important factor for a better user-interface and user-experience in an android application. In a wide series of articles on GeeksforGeeks for making a better UI, UX of an application, this is also going to be the one. In this article, we will know how to add crossfade animation between tw
4 min read
Content Placeholder Animation using Shimmer in Android
We have seen a unique design for loading screen which is seen in Facebook for loading purpose and it is also used to display the content placeholder for the purpose of loading. GitHub provides this type of loading placeholder, and it looks beautiful than the normal progress bar. In this article, we will take a look at the implementation of Content
6 min read
Content Placeholder Animation using Shimmer in Android with RecyclerView
We have seen the implementation of Content Placeholder Animation using Shimmer in Android for a simple view. In this article, we will take a look at implementing Content Placeholder Animation using Shimmer in Android with RecyclerView. What we are going to build in this article? We will be building a simple application in which we will be simply di
8 min read
Liquid Swipe Animation in Android
Liquid Swipe animation is used to slide the page like water which show different design and pattern on the screen. It creates a floating state. Liquid Swipe animation is a significantly trending design procedure. Movement can help keep clients inspired by your UI design longer and more motivated to collaborate with content. This method provides the
5 min read
Explode Animation in Android
In this article, we are going to show the android explode animation. This is something that is very interesting. You may have seen this feature in some game apps or even many money transfer apps. They show rewards like this. When you click on the reward it will explode and will show the reward that you have got. A sample GIF is given below to get a
2 min read
Typing Animation Effect in Android
In this article, we are going to implement a very important feature related to TextView. This feature can be used to show important announcements or notifications in an App. Even we can add this feature to show important links for the user as this attracts the attention of the user. So here we are going to learn how to implement that feature. A sam
3 min read
Pulse Animation View in Android
In this article, we are going to see the Pulse Animation feature. This feature can be used if we are downloading something from the server. Then till the time, it is downloading we can add this feature. A sample GIF is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using th
4 min read
Slide Animation in Android with Kotlin
Animations in Android allow UI elements to perform aesthetic moves across the screen. Animations can be implemented from a third party as well as developed from scratch. Despite the source, animations can be applied to any kind of view or UI element. Typically, we have demonstrated a slide animation, one from left to right and the other from right
3 min read
Background Color Transition Animation in Android
In Android, animations can be applied to any UI element to make the application look more appealing. There are many pre-defined animations available to use in Android. However, custom animations can be created in XML format and applied to UI elements. Once such animation is color transition and in this article, we shall implement a color-changing t
2 min read
Animation in LazyColumn and LazyRow in Android Jetpack Compose
Jetpack compose 1.1.0 just got released a few days ago, It added new features in which one of them was the ability to animate items in LazyRow and LazyColumn. In this article, we will see how to animate items in LazyColumn. Prerequisites: Knowledge of Kotlin.Knowledge of Jetpack Compose.Knowledge of LazyComposablesStep by Step Implementation Step 1
4 min read
How to Add Uber Car Animation in Android App?
Google Map is being used in a lot of applications these days. Many apps need google maps services for multiple purposes. Example of such apps is our daily life applications like Zomato, Swiggy and amazon uses google maps for delivery purposes while apps like uber and ola use maps for tracking the real-time location of the passenger and driver, In a
7 min read
How to Show and Hide a View with a Slide Up and Down Animation in Android?
View in android is an area of the screen which is responsible for drawing and event handling. The layout is a collection of views. It consists of some content like images, text, a button, or anything that an android app can display. In this article, we will take a look at how to show and hide a view in an Android Application. We have to create a vi
3 min read
Android Jetpack Compose - Rotation Animation
Jetpack Compose is a new UI toolkit from Google used to create native Android UI. It speeds up and simplifies UI development using less code, Kotlin APIs, and powerful tools. Prerequisites: Familiar with Kotlin and OOP Concepts as wellBasic understanding of Jetpack ComposeAndroid Studio Canary Version A sample video is given below to get an idea ab
8 min read
Background Color Transition Animation in Android Jetpack Compose
Many Android applications include an offer page or discount tags that change colors continuously to capture the attention of users. The principle underlying such bars/tags/coupons color shifting UI is the background color transition effect. In this post, we will look at how to create such background color transition effects. Prerequisites:Familiar
7 min read
How to Implement Fab Explosion Animation in Android?
When interacting with apps on our devices, animations add delight to the user's experience and create a sense of connection between the vibrant destinations. One of the animations on Android which enhances the user's experience is the FAB (Floating Action Button) Explosion Animation. Here, the user clicks the FAB and it explodes to fill the whole s
4 min read
Animation in Android with Example
Animation is the process of adding a motion effect to any view, image, or text. With the help of an animation, you can add motion or can change the shape of a specific view. Animation in Android is generally used to give your UI a rich look and feel. The animations are basically of three types as follows:  Property AnimationView AnimationDrawable A
8 min read
Flip Card Animation in Android
In this article, we are going to see how to build a Flip Card Animation app in Android Studio. Animation makes our app more attractive, convincing, and user-friendly. A sample GIF is given below to get an idea about what we are going to do in this article. Please note that we will be using Kotlin as the programming language.  Step-by-Step Implement
4 min read
How to Add Page Curl Animation Between Images in Android?
Animations are the best way to create a good looking user-interfaces. Users love to see animation in an android application. And this becomes even more necessary when we have to make some kind of special apps, For example, if we are creating an application for a book Then we should create an animation that gives a real-world feel to the user while
3 min read
How to Create Star Animation in Android?
In this article, we are going to create star animation using an animated star library. Here we will be creating a background drawable file and will specify the color for the animation. The star animation we have created is easy to create since we are using a library. A sample GIF is given below to get an idea about what we are going to do in this a
3 min read