1

我正在创建一个代码来显示文本动画(从上到下滑动)并且该文本每秒都在变化,我使用的是 CountDownTimer 和 textSwitcher。请参考下面的代码。

代码可以正常编译,但是一旦我尝试访问包含文本切换器的活动,它就会使应用程序崩溃。

 final TextSwitcher sec_sw = (TextSwitcher)findViewById(R.id.textSwitcher);
    sec_sw.setInAnimation(this, R.anim.slide_in_bottom);
    sec_sw.setOutAnimation(this, R.anim.slide_out_top);

    new CountDownTimer(differenceleft, 1000) { // adjust the milli seconds here

        public void onTick(long millisUntilFinished) {
            days_tv.setText(""+String.format("%02d", TimeUnit.MILLISECONDS.toDays(millisUntilFinished)));
            hours_tv.setText(""+String.format("%02d",TimeUnit.MILLISECONDS.toHours(millisUntilFinished)- TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(millisUntilFinished))));
            min_tv.setText("" + String.format("%02d", TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millisUntilFinished))));
            //sec_tv.setText("" + String.format("%02d", TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished))));
            sec_sw.setText("" + String.format("%02d", TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished))));

        }
        public void onFinish() {
            /*_tv.setText("done!");*/
        }
    }.start();
4

0 回答 0