如何在 Android 中创建 "fill-up" 动画

How to create a "fill-up" animation in Android

我正在尝试在 Android 中的形状上创建 "fill-up" 动画。它应该开始完全不可见,然后像这样从底部逐渐 "fill up":

我特别想要制作动画的是一个圆圈,如下所示:

<?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>

我已经检查了 AlphaAnimation、RotateAnimation、ScaleAnimation 和 TranslateAnimation(Animation 的子类),但我找不到为此使用它们的方法。

你可以深入研究动画,比如 drawPath 等。在这种情况下我应该做的更简单一点:
- 在屏幕上放置一个完整的红色圆圈
- 在上面放一个白色背景的视图(像一个正方形),覆盖所有的圆圈
- 使白色方块视图向上移动以显示您的圆圈
您可以使用简单的过渡动画来完成。
这样它看起来就像你想要的填充动画。
好吧,我的答案是根据您提供的图片给出的,它足够好地涵盖了目标。但是如果你希望进度条看起来像这样,你应该访问 https://github.com/snowdream/awesome-android 并检查那里的循环进度条库,至少你可能会学习如何实现你的目标或者找出它已经完成。

以下是我最终解决的方法:

我从 github https://github.com/lzyzsd/CircleProgress 中包含了这个库,其中包含一个圆形进度条 (CircleProgress)。我添加了一个倒数计时器以逐渐增加它显示的 "progress"

代码如下:

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();

感谢 Stan 为我指出圆形进度条!