2

I have an ImageSwitcher and I'm using it to create a slideshow. I can control the duration that an image is displayed for but how do I control the duration of the transition between the images. I want to increase that duration because the outAnimation of the previous image and the inAnimation of the next image, look like they merge and it doesn't look good.

Namratha
  • 16,630
  • 27
  • 90
  • 125

1 Answers1

4

Define custom in and out animations for your ImageSwitcher:

ImageSwitcher imageSwitcher = (ImageSwitcher) findViewById(R.id.ImageSwitcher);
imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
    R.anim.custom_fade_in));
imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
    R.anim.custom_fade_out));

and in your animation xmls set your duration:

<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
    ....
    android:duration="1000"/>
</set> 
Gunnar Karlsson
  • 28,350
  • 10
  • 68
  • 71
  • Thanks! Works like a charm. I only had to change the duration in XML. I can do it without a custom xml. I can use the ones provided by android with the ImageSwitcher API demo. But if you mean custom as having it bundled in your application and not using the built in android.R.anim. constant, then you're right :) – Namratha May 09 '12 at 07:24