如何在Android中创建“填充”动画

3
我正在尝试在Android上创建一个形状的“填充”动画。它应该开始完全不可见,然后逐渐从底部“填充”如下图所示: enter image description here 我要特别动画的是像这样的圆形:
<?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的子类),但是我找不到一种使用它们的方法来实现这个功能。


@Wallén 刚刚检查了一下,似乎图片已被删除。请上传一张新的图片。 - Santosh Joshi
2个回答

6
这是我最终解决的方法:
我从github上下载了这个库https://github.com/lzyzsd/CircleProgress,它包含一个圆形进度条(CircleProgress)。我添加了一个倒计时器来逐步增加其展示的“进度”。
以下是代码:
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向我介绍了循环进度条!

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

1
非常感谢您的回答!这似乎是个好主意。唯一的问题是,这样一个正方形会遮挡我圆圈上方的内容... - Fredrik Wallén

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接