图像切换器无法正常工作
image Switcher is not working properly
我有一个应该显示广告的 android 应用程序,这些广告是从服务器中提取的,然后保存在 phone 上,我制作了一个应该显示广告的方法,但不幸的是,它没有按预期工作它显示第一张图片很长时间然后循环太快我不知道为什么
这是我的方法
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 应用程序,这些广告是从服务器中提取的,然后保存在 phone 上,我制作了一个应该显示广告的方法,但不幸的是,它没有按预期工作它显示第一张图片很长时间然后循环太快我不知道为什么
这是我的方法
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();
}
}