Setting animation ImageSwitcher will run (in_left or out_right)
<p>I'm doing an image viewer that pass pictures to next or previous, by clicking right/left button.</p>

<p>I wanna to animate the transition between the pictures. I did it using ImageSwitcher, it is working, but I still have a problem.</p>

<p>The animation loaded is always the same, always sliding out right, making no difference if I click on right or left button. </p>

<p>QUESTION: How can I set which animation will run when I click my buttons?</p>

<p>I did my code based on this blog: <a href="http://saigeethamn.blogspot.com/2010/05/image-switcher-view-android-developer.html" rel="nofollow">http://saigeethamn.blogspot.com/2010/05/image-switcher-view-android-developer.html</a></p>

<p>Here same important parts of the code:</p>

<pre><code>// OnCreate()
in = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left);
out = AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right);

imageSwitcher = (ImageSwitcher) findViewById(R.id.imageSwitcher1);
imageSwitcher.setFactory(this);
imageSwitcher.setInAnimation(in);
imageSwitcher.setOutAnimation(out);
</code></pre>

<p>Now the click event (bm1 and bm2 are bitmaps):</p>

<pre><code>    private OnClickListener mClickListener = new OnClickListener() {
    @Override
    public void onClick(View v) {
        if (v.getId()==R.id.buttonRight) {
            Drawable d =new BitmapDrawable(getResources(),bm1);
            imageSwitcher.setImageDrawable(d);
        } else
        if (v.getId()==R.id.buttonLeft) {
            Drawable d =new BitmapDrawable(getResources(),bm2);
            imageSwitcher.setImageDrawable(d);
        }
    }
};
</code></pre>

<p>How the ImageSwitcher know witch animation it will perform? If is In Left or Out Right?</p>

<p>EDITED FROM HERE ----------------------------------------------------</p>

<p>Solution:</p>

<pre><code>private OnClickListener mClickListener = new OnClickListener() {
    @Override
    public void onClick(View v) {
        if (v.getId()==R.id.buttonRight) {
            imageSwitcher.setInAnimation(this, R.anim.slide_in_left); // added
            imageSwitcher.setOutAnimation(this, R.anim.slide_out_left); // added
            Drawable d =new BitmapDrawable(getResources(),bm1);
            imageSwitcher.setImageDrawable(d);
        } else
        if (v.getId()==R.id.buttonLeft) {
            imageSwitcher.setInAnimation(this, R.anim.slide_in_right); // added
            imageSwitcher.setOutAnimation(this, R.anim.slide_out_right); // added
            Drawable d =new BitmapDrawable(getResources(),bm2);
            imageSwitcher.setImageDrawable(d);
        }
    }
};
</code></pre>

<p>Based on the answer of Rui Gaspar. Need to create the xmls he shows. </p>
