动画textView再次更改文本和动画(动画倒计时)

时间:2012-05-29 17:37:51

标签: java android android-animation

我试图在android plataform上进行动画倒计时,在textView中显示数字3,从0到1.5在scale属性上成长,所以数字2,1和“GO!”。

我正在使用textView,动画和AnimationListener,但动画不能正常工作,它只能在显示数字3的第一个动画中工作,所以它显示“go!”这个词。没有动画。

我做错了什么?

谢谢!

这里是View counter.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_height="fill_parent" 

android:layout_width="fill_parent" android:gravity="center_vertical|center_horizontal">

    <TextView
        android:id="@+id/txtCount"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="3" android:textColor="#ffffff" android:textSize="150dp"/>

</LinearLayout>

<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:interpolator="@android:anim/linear_interpolator"
        android:fromXScale="0"
        android:toXScale="1.5"
        android:fromYScale="0"
        android:toYScale="1.5"
        android:fillAfter="false"
        android:duration="1000" />
</set>

我的代码:

public class AdivinhacaoActivity extends Activity {

...

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ...

    //async task
    new loaderImages(this).execute();
}

private class loaderImages extends AsyncTask<Void, String, Bitmap[]> {

    Activity activity;
    public loaderImages(Activity act){
        activity = act;
    }

    protected Bitmap[] doInBackground(Void... arg0) {       

        ...

        return list;
    }

...
    int countCounter;
    protected void onPostExecute(Bitmap[] imagens){
        bmps = imagens;
        carregaContagem();
        final Animation anima = AnimationUtils.loadAnimation(activity, R.anim.counter);         

        countCounter = 3;

        anima.setAnimationListener(new AnimationListener() {                

                    public void onAnimationStart(Animation anim){};                 
                    public void onAnimationRepeat(Animation anim){};

                    public void onAnimationEnd(Animation anim)
                    {                   
                //here I tried txtCount.clearAnimation() but it doesn't work
                        countCounter--;                 
                        if(countCounter >= 0){
                    //change the text
                            if(countCounter > 0){
                                txtCount.setText("" + countCounter);
                            }
                            else{
                                txtCount.setText("GO!");                            
                            }   
                    //start animation again with text changed  
                            txtCount.startAnimation(anim);
                        }
                        else{
                            ...
                        }
                    };
                });

        //start animation first time
        txtCount.startAnimation(anima);         

        }

    }

}

1 个答案:

答案 0 :(得分:0)

我管理解决了我的问题,为每个计数使用一个textView和一个动画实例,是的它可行,但我无法理解为什么我的原始解决方案不起作用的原因!