Java – How to create a “fill-up” animation in Android

How to create a “fill-up” animation in Android… here is a solution to the problem.

How to create a “fill-up” animation in Android

I’m trying to create a “fill” animation on a shape in Android. It should start completely invisible, and then gradually “fill” from the bottom like this:
enter image description here

What I especially want to animate is a circle like this :

<?xml version="1.0" encoding="utf-8"?>
<shape
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:shape="oval">

<solid 
       android:color="#666666"/>

<size 
       android:width="120dp"
       android:height="120dp"/>
</shape>

I’ve checked AlphaAnimation, RotateAnimation, ScaleAnimation, and TranslateAnimation (subclasses of Animation), but I can’t find a way to use them for this.

Solution

Here’s how I finally solved it:

I included this library from github https://github.com/lzyzsd/CircleProgress which contains a circular progress bar ( CircleProgress)。 I added a countdown timer to gradually increase the “progress” it shows

The code is as follows:

final CircleProgress circularProgress =(CircleProgress)findViewById(R.id.circleProgress);

Hides the text and the part of the circle which should not be shown
circularProgress.setUnfinishedColor(Color.parseColor("#00000000"));
circularProgress.setTextColor(Color.parseColor("#00000000"));

Makes the circle red
circularProgress.setFinishedColor("#FF0000");

final int timeToCountDownMilis = 10000;
circularProgress.setMax(timeToCountDownMilis);

Initiates and starts the countdowntimer which gradually increases the "progress" in the progress bar
new CountDownTimer(timeToCountDownMilis,70){

onTick(long milisUntilFinished){
       circularProgress.setProgress(timeToCountDownMilis-(int)milisUntilFinished);
    }

onFinish(){
    }
}.start();

Thanks to Stan for pointing out the circular progress bar for me!

Related Problems and Solutions