Search code examples
androidtimerslideshowandroid-imageimageswitcher

How to control duration of transition in ImageSwitcher Android


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.


Solution

  • 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>