I am a beginner when it comes to these things, so apologies if this is a simple question.
I am attempting to implement the ImageSwitcher to cycle through a set of images. To do this, I'm trying to implement the timer as described here: How to make an ImageSwitcher switch the image every 5 secs?
I have got the images cycling through just fine, however the image loads and then the animation takes place. Image 1 will be displayed then it will switch to image 2 then fade out image 2 and fade it back in again. Image 2 will then be displayed for the specified time, and the process repeats.
I want Image 1 to fade out, and then fade Image 2 in.
Here is what I have so far:
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));
The timer from the aforementioned question:
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);
And
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;
}
I would dearly appreciate some assistance.
You are setting setInAnimation() 2 times. You didn't set setOutAnimation().
Like:
imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in));
imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_out));