Thread.sleep()之后的转换?

时间:2015-01-30 00:57:28

标签: java android xml

我正在使用初始徽标活动编写应用程序。 它必须显示1秒钟,然后使用自定义转换启动主活动。

问题是徽标活动显示1秒钟,但动画总是标准的,很少显示我制作的自定义动画。

这是logoActivity.class中的代码:

        Thread thread;
        i = new Intent(this, mainActivity.class);
        thread=  new Thread(){
            @Override
            public void run(){
                try {
                    synchronized(this){
                        Thread.sleep(1000);
                    }
                }
                catch(InterruptedException ex){
                    Log.d("Event Loop", "Exception: " + ex.toString());
                }
                startActivity(i);
                overridePendingTransition(R.anim.anim_out, R.anim.anim_in);
                finish();
            }
        };

这是anim_out.xml中的代码:

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

<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_shortAnimTime"
android:fromXDelta="0%p"
android:toXDelta="100%p"></translate>

这是anim_in.xml中的代码:

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

<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_shortAnimTime"
android:fromXDelta="-100%p"
android:toXDelta="0%p"></translate>

我使用这些动画来设置来自mainActivity和secondActivity的自定义过渡,并且它完美地运行。

请帮我解决这个问题!

2 个答案:

答案 0 :(得分:0)

尝试使用比此方法更好的countDownTimer。

   CountDownTimer   timer = new CountDownTimer(1000,1000) {

            @Override
            public void onTick(long millisUntilFinished) {

            }

            @Override
            public void onFinish() {
                timer.cancel();
                timer = null;
                 startActivity(i);
                overridePendingTransition(R.anim.anim_out, R.anim.anim_in);
                finish();

            }
        };
        timer.start();

答案 1 :(得分:0)

我相信你的目的是在活动之间用自定义动画而不是单个图像显示一种SplashScreen。

这是一个关于如何做到这一点的优秀教程

  

http://www.codeproject.com/Articles/113831/An-Advanced-Splash-Screen-for-Android-App