簡體   English   中英

TextView不斷彈出

[英]TextView keeps popping up

我有一個活動,其中出現了TextView,然后消失了。 但是,每次淡出時,它都會彈出。

wtext.setText("");

但是然后我的文本消失了而沒有消失(消失后)。 有誰知道如何解決這個問題? 謝謝! 親切的問候。

這是我的代碼:

public class SplashScreen extends Activity {



protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);

    Handler handler = new Handler();

    final TextView wtext = (TextView) (findViewById(R.id.wtext));

    Animation animation = AnimationUtils.loadAnimation(this, R.anim.abc_fade_in);
    wtext.startAnimation(animation);

    Runnable task = new Runnable() {

                @Override
                public void run() {
                    Animation animation1 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.abc_fade_out);
                    wtext.startAnimation(animation1);
                    wtext.setText("");
                }
    };
    handler.postDelayed(task, 5000);

}

如果您希望動畫制作完成后發生某些事情(在這種情況下,隱藏文本視圖),則必須使用AnimationListener

Animation.AnimationListener myListener = new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                wtext.setVisibility(View.INVISIBLE);
            }

        };
animation1.setAnimationListener(myListener);

您可以使用ViewPropertyAnimator ,它會更改視圖的實際屬性,而不僅僅是外觀,因此在動畫完成后它不會跳回到原始狀態。

wtext.animate().alpha(0);

您可以嘗試在元素上將fillAfter標志設置為true :動畫完成后,它將對其應用最終的轉換。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM