35

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 to keep background activity to same position as it was, so that the new activity will seem as a overlay to background activity when open.

Here are my slide_in_up.xml

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

and slide_out_up.xml

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

How can I do that?
Thanks...

4

3 回答 3

56

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>

逗留.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" />

打开活动

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

关闭活动

finish();
overridePendingTransition(R.anim.stay, R.anim.slide_down);
于 2016-01-12T06:01:38.977 回答
53

然后提供一个传出动画,让当前的Activity保持静止:

overridePendingTransition(R.anim.slide_in_up, R.anim.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" />
于 2013-05-17T08:06:31.190 回答
2

你可以简单地打电话overridePendingTransition(R.anim.slide_in_up, 0)

0意味着没有动画。

于 2015-06-27T01:08:47.760 回答