how to change images on imageView after some interval

后端 未结 5 1766
再見小時候
再見小時候 2020-11-29 10:24

I have a problem that I want to paste images on ImageView in Android and that images are periodically changed after some interval. Means one by one images shown in ImageView

5条回答
  •  长情又很酷
    2020-11-29 11:23

    Try this it's working

    public class vv extends Activity { int b[] = {R.drawable.a, R.drawable.m, R.drawable.b, R.drawable.j, R.drawable.er, R.drawable.chan, R.drawable.vv}; public ImageView i; int z = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        i = (ImageView) findViewById(R.id.image);
        i.setImageResource(b[0]);
        Thread timer = new Thread() {
            public void run() {
                try {
                    sleep(2000);
    
                    for (z = 0; z < b.length + 2; z++) {
                        if (z < b.length) {
                            sleep(2000);
                            runOnUiThread(new Runnable() {
                                public void run() {
                                    i.setImageResource(b[z]);
                                }
                            });
                        } else {
                            z = 0;
    
                        }
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } finally {
                    System.out.println("finally");
                }
            }
        };
        timer.start();
    }
    

    }

提交回复
热议问题