ImageSwitcher在设置图像动画之前显示图像



当谈到这些事情时,我是一个初学者,所以如果这是一个简单的问题,我很抱歉。

我正在尝试实现ImageSwitcher来循环浏览一组图像。为了做到这一点,我试图实现这里描述的计时器:如何使ImageSwitcher每5秒切换一次图像?

我让图像循环通过得很好,但是图像加载,然后动画发生。图像1将被显示,然后它将切换到图像2,然后淡出图像2并再次淡入。然后,图像2将显示指定的时间,并重复该过程。

我希望图像1淡出,然后将图像2淡入。

以下是我目前所拥有的:

imageSwitcher = (ImageSwitcher) findViewById(R.id.welcome_image);
imageSwitcher.setFactory(this);
imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in));
imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out));

来自上述问题的计时器:

Timer t = new Timer();
//Set the schedule function and rate
t.scheduleAtFixedRate(new TimerTask() {
public void run() {
//Called each time when 1000 milliseconds (1 second) (the period parameter)
currentIndex++;
// If index reaches maximum reset it
if(currentIndex==messageCount)
currentIndex=0;
runOnUiThread(new Runnable() {
public void run() {

imageSwitcher.setImageResource(imageIDs[currentIndex]);
}
});
}
},1000,5000);

public View makeView() {
ImageView imageView = new ImageView(this);
imageView.setBackgroundColor(0x00000000);
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
imageView.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
return imageView;
}

我非常感谢你的帮助。

您正在设置setInAnimation()两次。您没有设置setOutAnimation()。

类似:

imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in));
imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,   
android.R.anim.fade_out));

最新更新