簡體   English   中英

圖像在Android中連續播放幻燈片

[英]slideshow of images continously in android

我想在Android中使用imageview以5秒的間隔連續顯示圖像。

我嘗試了以下代碼

String[] Img_data = { MediaStore.Images.Media.DATA };

   Cursor imgcursor = this.managedQuery(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI,    Img_data,null,null, null); 

         if(imgcursor!=null && img_cursor.getCount()>0){

           while(!imgcursor.isAfterLast()){

            imgcursor.moveToFirst();

              String filepath = cursor.getString(columnIndex);

              imageview.setImageUri(Uri.parse(filepath);
              imgcursor.moveToNext();
           }

         }

請給我相應的答案。

為此使用處理程序:

Handler mHandler = new Handler();
mHandler.postDelayed(mRunnable, 2000);

final Runnable mRunnable = new Runnable()
{
    @Override
    public void run()
    {

            Utility.getInstance(getActivity()).displayImage(mImageUrlsTop.get(mCounterTop++), mImageViewTop, mProgressBarTop);
            mHandler.postDelayed(mRunnable, 2000);                          
    }
};

在這里,displayImage是我的功能,用於顯示提供的URL和Imageview的圖像,而mImageUrlsTop是ImageUrl的數組列表。

試試這個代碼

 private Runnable updateImageThread = new Runnable() {

            public void run() {

                timeInMilliseconds = SystemClock.uptimeMillis() - startTime1;

                updatedTime = timeSwapBuff + timeInMilliseconds;

                int secs = (int) (updatedTime / 1000);
                int mins = secs / 60;
                secs = secs % 60;
                int milliseconds = (int) (updatedTime % 5000);
    // set images to imageview  here as per your need

                customHandler.postDelayed(this, 0);
            }

        };


// call this thread like this
private Handler customHandler = new Handler();
long timeInMilliseconds = 0L;
long updatedTime = 0L;
customHandler.postDelayed(updateImageThread, 0);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM