将 Android 图库用作自动幻灯片

2022-01-21 00:00:00 timer components android java gallery

您好,我想为应用创建启动画面,并让画廊在计时器上旋转几张图片.谁能告诉我如何使用计时器为图库中的图像设置动画?

Hi I want to create a splashscreen for an app, and have a gallery rotate several images on a timer. Can anyone show me how I could use a timer to animate the images in a Gallery?

推荐答案

一个简单的解决方案是

private int PicPosition;
private Handler handler = new Handler();

.........

private Runnable runnable = new Runnable() {
    public void run() {
        myslideshow();
        handler.postDelayed(this, 1000);\execute every second.
    }
};

    private void myslideshow()
    {
                    PicPosition = gallery.getSelectedItemPosition() +1;             
                    if (PicPosition >=  Pictures.size())            
                    PicPosition =  gallery.getSelectedItemPosition(); //stop 
                                    else
                    gallery.setSelection(PicPosition);//move to the next gallery element.
    }

相关文章