我可以更改了Android startActivity()过渡动画? [英] Can I change the Android startActivity() transition animation?
问题描述
我开始一个活动,宁愿有一个字母淡入为 startActivity()
,并淡出了完成( )
。我怎么能去这在Android SDK?
I am starting an activity and would rather have a alpha fade-in for startActivity()
, and a fade-out for the finish()
. How can I go about this in the Android SDK?
推荐答案
在其中执行完成()相同的语句,执行您的动画也有。然后,在新的活动,运行另一个动画。看到这个code:
In the same statement in which you execute finish(), execute your animation there too. Then, in the new activity, run another animation. See this code:
fadein.xml
fadein.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<alpha android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="500"/> //Time in milliseconds
</set>
在您完成级
private void finishTask() {
if(blabbla==blablabla){
finish();
runFadeAnimation();
}
}
private void runFadeInAnimation() {
Animation a = AnimationUtils.loadAnimation(this, R.anim.fadein);
a.reset();
LinearLayout ll = (LinearLayout) findViewById(R.id.yourviewhere);
ll.clearAnimation();
ll.startAnimation(a);
}
fadeout.xml
fadeout.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<alpha android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="500"/>
</set>
在新的活动类创建像我写的runFadeAnimation一个类似的方法,然后你的onCreate运行它,不要忘记改变资源ID来淡出。
In your new Activity-class you create a similiar method like the runFadeAnimation I wrote and then you run it in onCreate and don't forget to change the resources id to fadeout.
这篇关于我可以更改了Android startActivity()过渡动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!