Activity sliding from bottom to top but background activity should not moved

前端 未结 3 1950
温柔的废话
温柔的废话 2021-01-31 03:25

I am trying to slide an Activity from Bottom to Top which I am able to do.

But while sliding from bottom to top my background activity is also sliding to bottom. I want

相关标签:
3条回答
  • 2021-01-31 03:50

    You can simply call overridePendingTransition(R.anim.slide_in_up, 0)

    0 means no animation.

    0 讨论(0)
  • 2021-01-31 03:55

    slide_up.xml

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator">
    
        <translate
            android:duration="@android:integer/config_longAnimTime"
            android:fromYDelta="100%p"
            android:toYDelta="0" />
    
    </set>
    

    slide_down.xml

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator">
    
        <translate
            android:duration="@android:integer/config_longAnimTime"
            android:fromYDelta="0"
            android:toYDelta="100%p" />
    
    </set>
    

    stay.xml

    <?xml version="1.0" encoding="utf-8"?>
    <translate xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="@android:integer/config_longAnimTime"
        android:fromYDelta="0%p"
        android:toYDelta="0%p" />
    

    Open Activity

    startActivity(new Intent(FromActivity.this, ToActivity.class));
    overridePendingTransition(R.anim.slide_up, R.anim.stay);
    

    Close Activity

    finish();
    overridePendingTransition(R.anim.stay, R.anim.slide_down);
    
    0 讨论(0)
  • 2021-01-31 03:59

    Then provide an outgoing animation to make the current Activity stay still:

    overridePendingTransition(R.anim.slide_in_up, R.anim.stay);
    

    stay.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <translate xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="@android:integer/config_longAnimTime"
        android:fromYDelta="0%p"
        android:toYDelta="0%p" />
    
    0 讨论(0)
提交回复
热议问题