[英]Transition after Thread.sleep()?
我正在使用初始徽標活動對應用程序進行編程。 它必須顯示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的自定義過渡,並且效果很好。
請幫我解決這個問題!
嘗試使用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();
我相信您的意圖是在活動之間使用自定義動畫而不是單個圖像顯示一種SplashScreen。
這是有關如何執行此操作的出色教程
http://www.codeproject.com/Articles/113831/An-Advanced-Splash-Screen-for-Android-App
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.