如何在Android中赋予自上而下的动画效果? [英] How to give top to bottom animation in Android?
问题描述
当我进入下一个活动时,我可以从下至上制作动画,但是现在当我按回时,我使用相同的代码从上至下制作动画,但是它始终从下至上制作动画,所以我的问题是当我在android设备上按下后退按钮时,如何从上到下制作动画?
请在下面找到我的代码.
I am able to give bottom to top animation when I go to next activity but now when I pressed back I am using same code for giving animation from top to bottom animation but it always goes to bottom to top so my question is how to give animation from top to bottom when i pressed back button on android device?
Please find my code below.
我在使用Intent
从一个Activity
过渡到另一个Activity
的过程中使用它.
I use it during transitioning from one Activity
to another using an Intent
.
overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );
和xml是:slide_in_up.xml
and xml is: 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"/>
而slide_out_up.xml是
and slide_out_up.xml is
<?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"/>
推荐答案
只需在slide_out_up.xml中将-100更改为100(减去减号)
Just Change -100 to 100 (remove minus) in slide_out_up.xml
@Override
public void onBackPressed() {
finish();
overridePendingTransition(R.anim.enter_anim, R.anim.exit_anim);
}
这篇关于如何在Android中赋予自上而下的动画效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!