Now this specific page does describe a way to animate between layouts of different activities, but the problem is that the API is only supported for android 5.0 and higher, so I'd like to know what are the ways in which animation(like transition or any other type of fade/slide in etc.) could be done for layouts in two different activities.
You can't set transitions on your theme prior to Lollipop version but you can still use animations programmatically.
Here’s an example with animations that slide the new activity in when first created, and the opposite movement when you press the back button.
left_in.xml
<set>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="-100%"
android:toXDelta="0"
android:interpolator="@android:anim/decelerate_interpolator"
android:duration="500"/> //in milliseconds
</set>
right_in.xml
<set>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="100%"
android:toXDelta="0"
android:interpolator="@android:anim/decelerate_interpolator"
android:duration="500"/>
</set>
left_out.xml
<set>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0"
android:toXDelta="-100%"
android:interpolator="@android:anim/decelerate_interpolator"
android:duration="500"/>
</set>
right_out.xml
<set>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0"
android:toXDelta="100%"
android:interpolator="@android:anim/decelerate_interpolator"
android:duration="500"/>
</set>
On your activities you can call the animations as follows:
On start: overridePendingTransition(R.anim.right_in, R.anim.left_out);
On Back Pressed: overridePendingTransition(R.anim.left_in, R.anim.right_out);
Or any combination of the above.
Note that the first animation on overridePendingTransition
is for the incoming activity and the second for the outgoing activity.