简体   繁体   中英

android animating switching between activities - windows order

I'm following this how to DevBytes: Window Animations to implement translation as an animation when switching between activities.

Everything is working fine except animation when user presses back button from SUBACTIVITY to go to MAIN ACTIVITY. When MAIN ACTIVITY slides in it is under the SUBACTIVITY and i would like it be on top of it.

I use overridePendingTransition() to create animation when user goes back to MAIN ACTIVITY.

overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_right);

slide_in_right.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="-100%p" android:toXDelta="0"
    android:duration="3500" /> 
</set>

slide_out_right.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate xmlns:android="http://schemas.android.com/apk/res/android"
        android:fromXDelta="0" android:toXDelta="50%p"
        android:duration="3500" />
</set>

How can i reorder windows during animation so MAIN ACTIVITY is on top?

I had the same question. I was able to get my animation working smoothly and looking nice using the following animations with overridePendingTransition() in the sub-activity's finish() :

slide_in_right.xml:

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="-50%p" android:toXDelta="0"
    android:duration="300" />

slide_out_right.xml:

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="0" android:toXDelta="100%p"
    android:duration="300" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM