我可以更改 Android startActivity() 过渡动画吗? [英] Can I change the Android startActivity() transition animation?

查看:32
本文介绍了我可以更改 Android startActivity() 过渡动画吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开始一项活动,并且希望 startActivity() 的 alpha 淡入和 finish() 的淡出.我该如何在 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?

推荐答案

在执行finish() 的同一语句中,也执行你的动画.然后,在新活动中,运行另一个动画.请参阅此代码:

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:

淡入淡出.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".equals("blablabla"){
        finish();
        runFadeInAnimation();
    }
}

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);   
}

淡出.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>

在新的 Activity 类中,您创建一个类似的方法,例如我编写的 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆