Aug 3, 2012

Apply translate effect in activity transition

Create XML files to define shift in/shift out effect:

/res/anim/shift_in.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:fromXDelta="-100%"
    android:toXDelta="0.0"
    android:duration="1000" />


/res/anim/shift_out.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:fromXDelta="0.0"
    android:toXDelta="100%"
    android:duration="1000" />


Apply the effect to activity by calling overridePendingTransition(R.anim.shift_in, R.anim.shift_out).
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        overridePendingTransition(R.anim.shift_in, R.anim.shift_out);
    }



No comments:

Post a Comment

Infolinks In Text Ads