[英]slideshow of images continously in android
I want to display images continuously with 5 seconds gap using imageview in android. 我想在Android中使用imageview以5秒的间隔连续显示图像。
I have tried following code 我尝试了以下代码
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();
}
}
Please send me the appropriate answer for this question. 请给我相应的答案。
Use Handler for this as below :- 为此使用处理程序:
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);
}
};
Here displayImage is the my function to display image for provided URL and Imageview & mImageUrlsTop is the arraylist of ImageUrl's. 在这里,displayImage是我的功能,用于显示提供的URL和Imageview的图像,而mImageUrlsTop是ImageUrl的数组列表。
try this code 试试这个代码
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.