所有图片的背景同时改变。我必须一个一个地更改,在每张图片后等待5秒钟,再更改另一张,
ImageView[] imajlar={img1,img2,img3,img4,img5,img6,img7,img8};
for (final ImageView resmi:imajlar) {
//resmi.startAnimation(fadeout);
new CountDownTimer(16000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
resmi.setBackground(hediye);
resmi.startAnimation(fadein);
onPause();
}
@Override
public void onFinish() {
}
}.start();
答案 0 :(得分:3)
为此使用Handler
。希望对您有帮助。
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
changeImage();
}
}, 5000);
答案 1 :(得分:1)
尝试此代码。
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// define your code..
}
},5000);
答案 2 :(得分:1)
喜欢做
定义图像数组。
String img[]={img1,img2,img3};
和一个变量
int i=0;
现在在您的方法中
changeImage()
{
if(i<img.length())
{
//Pseudo code(your logic of setting image)
setImage.array[i];
i++;
}
else
{
//This is to start again;
i=0
}
}
然后在您定义的处理程序中。
final Handler mHandler=new Handler();
ha.postDelayed(new Runnable() {
@Override
public void run() {
changeImage();
mHandler.postDelayed(this, 5000);
}
}, 5000);
答案 3 :(得分:1)
使用处理程序尝试计时器
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
//Your code
}
}, 0, 5000);
答案 4 :(得分:0)
int totalImageSize = yourTotalImageCount;
final Handler mHandler = new Handler();
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
changeYourImage(totalImageSize);// this will give the position of image to add/remove
totalImageSize - 1;
if(totalImageSize > 0)
mHandler.postDelayed(this, 5000);
}
}, 5000);
}