-1

このコードは、テキストの色を 200 ミリ秒ごとに均等に変更するためのものです。最初のバージョンの変更が不均一/ちらつきで、2 番目のバージョンが均等に変更されるのはなぜですか?

               //first version
                long lt = System.currentTimeMillis(); 
                TextView tv = ...   
                 for (int i = 1; i < 120; i++) {
                final int cl = i % 2 == 0 ? 0xFFFF0000 : 0x00000000;
                Message w = Message.obtain(handler, new Runnable() {
                    public void run() {
                        tv.setTextColor(cl);
                        tv.requestLayout();

                    }
                });

                handler.sendMessageDelayed(w,i * 200L - (System.currentTimeMillis()-lt));

            }

                 //second version
            Animation anim = new AlphaAnimation(0.0f, 1.0f);
            anim.setDuration(200); //You can manage the time of the blink with this parameter
            anim.setStartOffset(20);
            anim.setRepeatMode(Animation.RESTART);
            anim.setRepeatCount(Animation.INFINITE);
            tv.startAnimation(anim);
4

1 に答える 1

1

アニメーションを作成/使用する前に、この問題が発生しました。アニメーションが終了したら、単に を呼び出しますclearAnimation()

これにより、完全に停止し、ユーザーが望むエクスペリエンスをユーザーに提供することができます。

アニメーションを停止する方法 (cancel() が機能しない)

続きを読む:

http://developer.android.com/reference/android/view/View.html

よろしく、

于 2013-05-25T03:32:39.213 に答える