I am facing a problem .
I have three activities and i need to start new activity with slide left.
Activity1
Activity2
Activity3
means
A Better approach is to create a style as follows:
<style name="mytheme" parent="@android:style/Theme.Black">
<item name="android:windowAnimationStyle">@style/theme</item>
</style>
<style name="theme">
<item name="android:windowEnterAnimation">@anim/fade_in</item>
<item name="android:windowExitAnimation">@anim/fade_out</item>
</style>
Then apply this style to your activity in manifest file using the android:theme tag.
call overridePendingTransition
before starting the SecondActivity. It takes as parameters two int enterAnim, exitAnim
.
I'll try to help you with the following example:
res/anim/trans_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>
res/anim/trans_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>
res/anim/trans_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>
res/anim/trans_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>
src/Activity2
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_traces);
overridePendingTransition(R.anim.trans_left_in, R.anim.trans_left_out);
...}
@Override
public void onBackPressed() {
super.onBackPressed();
overridePendingTransition(R.anim.trans_right_in, R.anim.trans_right_out);
}
Here it is,
Intent intent=new Intent(Activity1.this,Activity2.class);
startActivityForResult(intent,0);
getActivity().overridePendingTransition( R.anim.righttoleft, R.anim.stable );
And here is the animation righttoleft.xml,
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<translate
android:duration="500"
android:fromXDelta="-100%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="0%" />
</set>
and stable.xml
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="1.0" android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="500"
android:repeatCount="0"/>
</set>
Start activity and then just apply transition effect. For more info, how to proceed for this just visit here and for source code example visit this. For any query, feel free to comment.