【问题标题】:Countdown Timer on asset folder image资产文件夹图像上的倒数计时器
【发布时间】:2018-10-21 16:34:06
【问题描述】:

我想问一下如何实现倒数计时器来加载资产文件夹中的所有图像并根据设置的倒数时间显示它。例如,我的资产文件夹中有 5 张图像,我将它们放入数组中。每隔 5 秒,它将显示每个图像。例如:图像 1> 5 秒通过> 图像 2> 5 秒通过 > 图像 3 等等......

下面是我的代码。请与我分享您的知识或任何实施方式。谢谢。

public class MainActivity extends AppCompatActivity {

private VrPanoramaView mVRPanoramaView;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

   mVRPanoramaView = (VrPanoramaView) findViewById(R.id.vrPanoramaView);

    loadPhotoSphere();


}

private void loadPhotoSphere() {

    VrPanoramaView.Options options = new VrPanoramaView.Options();
    InputStream inputStream = null;


    AssetManager assetManager=getAssets(); // to reach asset
    try {
        String[] images = assetManager.list("img");// to get all item in img folder.

        options.inputType = VrPanoramaView.Options.TYPE_MONO;

        for (int i = 0; i < images.length; i++) // the loop read all image in img folder 
        {
            inputStream = getAssets().open("img/" + images[i]);

            mVRPanoramaView.loadImageFromBitmap(BitmapFactory.decodeStream(inputStream), options);

        }
        }catch (IOException e) {
            // you can print error or log.
            e.printStackTrace();
        }


}

}

【问题讨论】:

    标签: android countdowntimer google-vr android-assetmanager


    【解决方案1】:

    解决方案:

    您可以使用Handler 完成此操作,如下所示:

    Handler h = new Handler();
    int delay = 5*1000; //1 second = 1000 milisecond, 5 * 1000 = 5seconds
    Runnable runnable;
    
    @Override
    protected void onResume() {
       //start handler as activity become visible
    
        h.postDelayed( runnable = new Runnable() {
            public void run() {
    
                // do the setting of image here
    
                h.postDelayed(runnable, delay);
            }
        }, delay);
    
        super.onResume();
    }
    
    @Override
    protected void onPause() {
        h.removeCallbacks(runnable); //stop handler when activity not visible
        super.onPause();
    }
    

    希望对你有帮助,如有问题请评论。

    【讨论】:

    • 我试过了,还是不行,能不能详细解释一下?我对代码进行了一些更改,您能否查看并分享您的解决方案?谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    • 1970-01-01
    • 2015-02-06
    • 1970-01-01
    • 2021-10-15
    • 2017-05-06
    相关资源
    最近更新 更多