我希望使用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();
}
}
请将此问题的相应答案发给我。
答案 0 :(得分:1)
使用Handler进行如下操作: -
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的arraylist。
答案 1 :(得分:1)
试试这段代码
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);