Reputation: 1133
I am working on an Android app. I want to implement such animation on activity that if we leave activity A
then it should slide to left and new activity B
should slide in from right. And again when I leave current activity B
it should slide to right as well and previous activity A
should slide in from Left to Right. How is that possible ?
By the way I am using following code but it doesn't do anything..
overridePendingTransition(R.anim.slide_left_in, R.anim.slide_left_out);
I have written some XML code for Animation slides as below :
slide_left_in.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="@android:integer/config_shortAnimTime" />
</set>
slide_left_out.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="@android:integer/config_shortAnimTime" />
</set>
Your Help would be appreciate. Thank you!
Upvotes: 0
Views: 3878
Reputation: 9056
For the following animation you require these 4 anim xml.....
right_in.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="@android:integer/config_longAnimTime"/>
</set>
right_out.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="@android:integer/config_longAnimTime"/>
</set>
left_in.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="@android:integer/config_longAnimTime"/>
</set>
left_out.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="@android:integer/config_longAnimTime"/>
</set>
and use these code with the AcitvityA ...
intent = new Intent(this, AcitvityB.class);
startActivity(intent);
overridePendingTransition( R.anim.left_in, R.anim.left_out);
and use these in AcitvityB for BACK
@Override
public void onBackPressed() {
super.onBackPressed();
overridePendingTransition( R.anim.right_in, R.anim.right_out);
}
Output:-
NOTE:- If you need it opposite animation just change right instead of left and vice versa ......
Upvotes: 12