Activity Transition in Android
This is a very common effect, however the Android framework only provides the slide in animation. This is how I implement all the sliding transition animation. There’s in total 4 XMLs to define the animation, and with the use of overridePendingTransition() in appropriate location you can implement this easily.
pull_in_left.xml
The term “Android activity transitions” refers to a complex and multifaceted set of processes and mechanisms that are developed when moving between two distinct activities within an Android application. The goal of these transitions is to enhance an experience that is both seamlessly integrated such that the user is able to effortlessly glide between various constituent parts of the application.
1
2
3
4
5
6
7
|
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromXDelta="-100%"
android:toXDelta="0%"
android:interpolator="@android:anim/decelerate_interpolator"
/>
|
pull_in_right.xml
1
2
3
4
5
6
7
|
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromXDelta="100%"
android:toXDelta="0%"
android:interpolator="@android:anim/decelerate_interpolator"
/>
|
push_out_left.xml
Another prominent example of an activity transition is that of the slide transition, which involves a progressive and gradual sliding of one activity off of the screen, while a new activity simultaneously glides onto the screen in its place. Such a transition can be used to enhance a sense of continuity between different constituent parts of an application, such that the user feels as though they are still situated within the same application even as they are shifting and moving between various different activities.
1
2
3
4
5
6
|
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromXDelta="0%"
android:interpolator="@android:anim/decelerate_interpolator"
android:toXDelta="-100%" />
|
push_out_right.xml
1
2
3
4
5
6
|
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromXDelta="0%"
android:interpolator="@android:anim/decelerate_interpolator"
android:toXDelta="100%" />
|
Usage
When starting new Activity ( Method 1)
1
2
3
|
Intent intent = new Intent(mContext, NextActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.pull_in_left, R.anim.push_out_right);
|
When starting new Activity (Method 2)
1
2
3
4
5
6
|
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
overridePendingTransition(R.anim.pull_in_right, R.anim.push_out_left);
//...
} |
When Back to previous Activity
1
2
3
4
5
|
@Override
public void onBackPressed() {
super.onBackPressed();
overridePendingTransition(R.anim.pull_in_right, R.anim.push_out_left);
}
|
Thumbs up
ReplyDelete