我有一个应该显示广告的 Android 应用程序,这些广告是从服务器中提取的,然后将它们保存在手机上,我制作了一个应该显示广告的方法,但不幸的是,它没有按预期工作,它显示了第一张图片很长一段时间然后它循环得太快我不知道为什么
这是我的方法
private void startShowAds(final ArrayList<Ad> adArrayList) {
Handler handler = new Handler();
for (int i = 0; i < adArrayList.size(); i++) {
Ad ad = adArrayList.get(i);
Runnable runnable = new Runnable() {
public void run() {
imageView.setBackgroundDrawable(getBitMap(ad.getFileUri()));
handler.postDelayed(this, ad.getDuration());
}
};
handler.postDelayed(runnable, ad.getDuration());
}
startShowAds(dbHelper.getAllAdRecords(longitude, latitude));
}
任何帮助将不胜感激
最佳答案
试试这个:
private void startShowAds(final ArrayList<Ad> adArrayList) {
Handler handler = new Handler();
long offset = 0;
for (int i = 0; i < adArrayList.size(); i++) {
Ad ad = adArrayList.get(i);
Runnable runnable = new Runnable() {
public void run() {
imageView.setBackgroundDrawable(getBitMap(ad.getFileUri()));;
}
};
handler.postDelayed(runnable, offset);
offset += ad.getDuration();
}
}
关于android - 图像切换器无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46063894/