我正在使用两个imageview win,我想使用两个countdowntimer。 1个计时器在1000毫秒处显示1张图像,此后另一个倒数计时器启动并显示2张图像,第二张图像在另一个屏幕上显示之后,但我将其与单个countdowntimer一起使用。如何在课堂上使用2个倒数计时器?这是我的代码:

public class MainActivity extends Activity {
    private ImageView image1,image2;
    CountDownTimer countdown1,countdown2;
    int a = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.aaa);

        image1=(ImageView)findViewById(R.id.image1);
        image2=(ImageView)findViewById(R.id.image2);

        image1=(ImageView)findViewById(R.id.image1);
        image2=(ImageView)findViewById(R.id.image2);
        image1.setVisibility(View.VISIBLE);
        image2.setVisibility(View.INVISIBLE);

        new CountDownTimer(3000, 1000) {


            public void onTick(long millisUntilFinished) {


                if(a == 0)
                {
                    image1.setVisibility(View.VISIBLE);
                    image2.setVisibility(View.INVISIBLE);
                }
                else {

                } a++;

            }

            public void onFinish() {

                image2.setVisibility(View.VISIBLE);
                image1.setVisibility(View.VISIBLE);
                Intent i=new Intent(MainActivity.this,NextActivity.class);
                startActivity(i);
            }
        }.start();



    }
}

最佳答案

我不确定我是否理解请求,但是我会尝试这样的事情:

public class MainActivity extends Activity {
    private ImageView image1,image2;
    int a = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.aaa);

        image1=(ImageView)findViewById(R.id.image1);
        image2=(ImageView)findViewById(R.id.image2);
        image1.setVisibility(View.VISIBLE);
        image2.setVisibility(View.INVISIBLE);

        new CountDownTimer(4000, 1000) {
            public void onTick(long millisUntilFinished) {
                if(a == 0) {
                    image1.setVisibility(View.VISIBLE);
                } else if(a == 1) {
                    image1.setVisibility(View.INVISIBLE);
                    image2.setVisibility(View.VISIBLE);
                }
                a++;
            }
            public void onFinish() {
                Intent i=new Intent(MainActivity.this,NextActivity.class);
                startActivity(i);
            }
        }.start();
    }
}

10-08 19:05