如何在幻灯片中显示暂停/播放功能

时间:2014-03-13 15:05:21

标签: android multithreading slideshow

我有几张图片,我以幻灯片形式显示。每张图片后我都有一张空白图片。代码工作正常。我希望将播放/暂停功能放入其中。就像当用户在幻灯片放映之间触摸屏幕时,它应该暂停,并且应该显示一个按钮以进行播放/暂停。这是我的代码:

public class TatSlideShow extends Activity {

int count = 1;
private ImageView tatslide;
int i = 0;
int imgid[] = { R.drawable.tata1, R.drawable.tata2, R.drawable.tata3,
        R.drawable.tata4, R.drawable.tata5 };
RefreshHandler refreshHandler = new RefreshHandler();

class RefreshHandler extends Handler {
    @Override
    public void handleMessage(Message msg) {
        // TODO Auto-generated method stub
        TatSlideShow.this.updateUI();
    }

    public void sleep(long delayMillis) {
        this.removeMessages(0);
        sendMessageDelayed(obtainMessage(0), delayMillis);
    }
};

public void updateUI() {

    refreshHandler.sleep(3000);

    if ((count & 1) == 0) {

        tatslide.setImageResource(0);
        count++;
    } else {

        if (i < imgid.length) {
            tatslide.setImageResource(imgid[i]);

            // imageView.setPadding(left, top, right, bottom);
            i++;
            count++;
        }
    }

}

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tatslideshow);

    this.tatslide = (ImageView) this.findViewById(R.id.tatslide);
    updateUI();
}

}

0 个答案:

没有答案