Skip to content Skip to sidebar Skip to footer

Setting Animation ImageSwitcher Will Run (in_left Or Out_right)

I'm doing an image viewer that pass pictures to next or previous, by clicking right/left button. I wanna to animate the transition between the pictures. I did it using ImageSwitche

Solution 1:

You can implement your own animation

slide_in_left.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="100%p" android:toXDelta="0"
               android:duration="350"/>
</set>

slide_in_right.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="-100%p" android:toXDelta="0" 
               android:duration="350"/>
</set>

slide_out_left.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="0" android:toXDelta="-100%p" 
               android:duration="350"/>
</set>

slide_out_right.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="0" android:toXDelta="100%p" 
               android:duration="350"/>
</set>

You can use it like this:

//Switch Left
Intent myIntent = new Intent(m_context, MyActivity.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(myIntent);
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left);

//Switch Right  
Intent myIntent = new Intent(m_context, MyActivity.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(myIntent);
overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_right);

Post a Comment for "Setting Animation ImageSwitcher Will Run (in_left Or Out_right)"