我成功创建了活动之间的滑动动画,新的活动从下至上滑动。问题:向上滑动时,它会将旧活动“推”到外面以占据其空间。我想创建一个动画,该动画不会移动旧活动,而只会在旧活动静止不动时从旧活动的底部向上滑动。
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)
}
是否有可能在旧活动不移动时使新活动从下往上滑动?
请参阅有关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>