Snippets

cutiko Cool Transitions between Activities

Created by cutiko last modified
/*Common example*/
    overridePendingTransition(R.transition.slide_in_left, R.transition.slide_out_left);

/*Override Pending Transition for ActionBar back button*/
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        if (item.getItemId() == android.R.id.home) {
            finish();
            overridePendingTransition(R.transition.slide_out_left, R.transition.slide_in_left);
            return true;
        }
        return false;
    }
/*slide_in_left.xml*/

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="-100%p" android:toXDelta="0" android:duration="400" />
    <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="100" android:startOffset="200" />
</set>

/*slide_out_left.xml*/
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="0" android:toXDelta="-100%p" android:duration="400" />
    <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="100" android:startOffset="200" />
</set>

/*fade_in.xml*/
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="300"
    android:fromAlpha="0.0"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:toAlpha="1.0" />
    
/*right_slide_out.xml*/
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator">
    <translate
        android:duration="200"
        android:fromXDelta="0"
        android:toXDelta="100%p" />
</set>

/*slide_up.xml*/
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/decelerate_interpolator"
    android:shareInterpolator="true">
    <translate android:fromYDelta="100%p" android:toYDelta="0%p" android:duration="500" />
    <alpha xmlns:android="http://schemas.android.com/apk/res/android"
       android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="400"/>
</set>

/*slide_down.xml*/
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/decelerate_interpolator"
    android:shareInterpolator="true">
    <translate android:fromYDelta="0%p" android:toYDelta="100%p" android:duration="500" />
    <alpha xmlns:android="http://schemas.android.com/apk/res/android"
       android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="500"/>
</set>

Comments (0)