Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android动画闪烁_Java_Android - Fatal编程技术网

Java Android动画闪烁

Java Android动画闪烁,java,android,Java,Android,该代码用于使文本颜色每200ms均匀变化一次。为什么第一个版本的颜色变化不均匀/闪烁,而第二个版本的颜色变化均匀 //first version long lt = System.currentTimeMillis(); TextView tv = ... for (int i = 1; i < 120; i++) { fi

该代码用于使文本颜色每200ms均匀变化一次。为什么第一个版本的颜色变化不均匀/闪烁,而第二个版本的颜色变化均匀

               //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);
//第一版
long lt=System.currentTimeMillis();
文本视图电视=。。。
对于(int i=1;i<120;i++){
最终整数cl=i%2==0?0xFFFF0000:0x00000000;
Message w=Message.get(处理程序,new Runnable(){
公开募捐{
彩色电视机;
tv.requestLayout();
}
});
handler.sendMessageDelayed(w,i*200L-(System.currentTimeMillis()-lt));
}
//第二版
动画动画=新的AlphaAnimation(0.0f,1.0f);
动画设定持续时间(200)//您可以使用此参数管理闪烁时间
动画设置开始偏移(20);
动画设置重复模式(动画重新启动);
anim.setRepeatCount(Animation.INFINITE);
电视动画;

我以前在创建/使用动画时遇到过这个问题。完成动画后,只需调用
clearAnimation()

               //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);
这将确保它已经完全停止,应该是好的和顺利的,给用户你想要的体验

               //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);

               //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);
阅读更多:

               //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);

               //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);

关于,

最有可能是因为存储了
动画
,并且系统知道它将多次重画,而
消息
的任务要重得多,并且不是为类似的事情而设计的。
               //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);