Анимированный текстПросмотреть текст и снова оживить (анимированный обратный отсчет)

1

Я пытаюсь сделать анимированный обратный отсчет на андроиде plataform, который показывает номер 3 в textView, растущий от 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);         

        }

    }

}
Теги:
android-animation

1 ответ

0

Мне удалось решить мою проблему, используя один textView и один экземпляр анимации для каждого подсчета, да, это работает, но я не мог понять, почему причина, по которой мое оригинальное решение не срабатывало!

Ещё вопросы

Сообщество Overcoder
Наверх
Меню