在活动之间从下至上滑动动画

问题描述 投票:0回答:1

我成功创建了活动之间的滑动动画,新的活动从下至上滑动。问题:向上滑动时,它会将旧活动“推”到外面以占据其空间。我想创建一个动画,该动画不会移动旧活动,而只会在旧活动静止不动时从旧活动的底部向上滑动。

slide_in_up.xml:

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="@android:integer/config_mediumAnimTime"
        android:fromYDelta="100%p"
        android:toYDelta="0" />
</set>

slide_out_down.xml:

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="@android:integer/config_mediumAnimTime"
        android:fromYDelta="0"
        android:toYDelta="-100%p" />
</set>

使用幻灯片开始新活动的功能:

override fun startEditProfile() {
    startActivity(EditProfileActivity.newIntent(this))
    overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_down)
}

是否有可能在旧活动不移动时使新活动从下往上滑动?

android xml android-animation
1个回答
0
投票

请参阅有关overridePendingTransition两个参数的源代码注释:

 @param enterAnim A resource ID of the animation resource to use for
 the incoming activity.  Use 0 for no animation.
 @param exitAnim A resource ID of the animation resource to use for
 the outgoing activity.  Use 0 for no animation.

因此,如果您希望退出(旧)活动不移动,请将退出动画更改为该动画

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="@android:integer/config_mediumAnimTime"
        android:fromXDelta="0%"
        android:toXDelta="0%"
        android:fromYDelta="0%"
        android:toYDelta="0%" />
</set>
© www.soinside.com 2019 - 2024. All rights reserved.