I'm trying to achieve the following.
I want to slide activity 2 in with a click on btn1 and want to slide activity2 out again with a click on btn2 as shown in the following image:
I try to do so using the following (c#) code; java equivelant should be somewhat similar:
//MainActivity
btn1.Click += (object sender, EventArgs e) => {
var stationActivity = new Intent(_mainActivity, typeof(StationInfoActivity));
StartActivity(stationActivity);
_mainActivity.OverridePendingTransition(Resource.Animation.slide_1_enter, Resource.Animation.slide_1_exit);
//I have a reference to the _mainActivity since this activity is technically a fragment
};
//StationActivity
btn2.Click += (object sender, EventArgs e) => {
var mainIntent = new Intent(this, typeof(MainActivity));
StartActivity(mainIntent);
this.OverridePendingTransition(Resource.Animation.slide_2_enter, Resource.Animation.slide_2_exit);
};
And the following resource files:
//slide_1_enter
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromYDelta="100%p" android:toYDelta="0%p"
android:duration="@android:integer/config_shortAnimTime"/>
//slide_1_exit
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromYDelta="0%p" android:toYDelta="0%p"
android:duration="@android:integer/config_longAnimTime" />
//slide_2_enter
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromYDelta="0%p" android:toYDelta="0%p"
android:duration="@android:integer/config_longAnimTime" />
//slide_2_exit
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromYDelta="0%p" android:toYDelta="100%p"
android:duration="@android:integer/config_longAnimTime" />
The sliding in (slide_1_enter + slide_1_exit) is working perfectly, however, I can't figure out how to create the slide out animation (slide_2_enter + slide_2_exit). I don't visually see the exit animation. This is probably because of the following:
- MainActivity is visible (z-index: 0).
- StationActivity is launched with btn1.Click and animates over activity 1, using slide_1_enter.
- StationActivity is visible (z-index: 1)
- When clicking on btn2, MainActivity will launch, but it will be placed ON TOP OF StationActivity (getting z-index: 3), and thus preventing to see the exit animation (slide_2_exit)
So, unless I'm able to change the "z-index" of activities, this will not work, right?.
Is there a solution? Or any other suggestion? I'm afraid that the "easiest" way to get this working is to use a viewpager, but I rather would not want to implement this, because activity1 is already within a viewpager, and things would get way more complicated.