2011-08-06 57 views
0

在iOS系統中,我會做這樣的:我需要做一個啓動畫面

splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 768, 1024)]; 
splashView.image = [UIImage imageNamed:@"Default.png"]; 
[window addSubview:splashView]; 
[window bringSubviewToFront:splashView]; 

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:3.5]; 
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:window cache:YES]; 
[UIView setAnimationDelegate:self]; 
[UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)]; 
splashView.alpha = 0.0; 
splashView.frame = CGRectMake(-60, -60, 900, 1200); 
[UIView commitAnimations]; 

然後「推」視圖控制器去。

我已經看過各種實例和教程,不能讓上需要什麼樣的代碼句柄:(?動作)

  1. 顯示啓動畫面
  2. 讓它淡出
  3. 有另一種看法顯示。

有人發佈了這個我適應但評論代碼產生錯誤。我肯定錯過了什麼。

+0

我不能幫你那裏,除了表明沒有人喜歡閃屏和你真的不應該打擾做一個。這是用戶會忽略或輕微惱火的一個功能。 – kwatford

+0

有很多的例子,http://stackoverflow.com/questions/6918430/splash-screenhow-to-show-an-image-in-full-screen/6918484#6918484 – 2011-08-06 15:18:01

回答

1
public class SplashScreen extends Activity { 
protected boolean _active = true; 
protected int _splashTime = 3000; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    setContentView(R.layout.splash); 

    // thread for displaying the SplashScreen 
    Thread splashTread = new Thread() { 
     @Override 
     public void run() { 
      try { 
       int waited = 0; 
       while (_active && (waited < _splashTime)) { 
        sleep(100); 
        if (_active) { 
         waited += 100; 
        } 
       } 
      } catch (InterruptedException e) { 
       // do nothing 
      } finally { 
       finish(); 
       startActivity(new Intent(
         "com.android.NextActivity")); 
      } 
     } 
    }; 
    splashTread.start(); 
} 

@Override 
public boolean onTouchEvent(MotionEvent event) { 
    if (event.getAction() == MotionEvent.ACTION_DOWN) { 
     _active = false; 
    } 
    return true; 
} 

}

和splash.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 
<ImageView android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:src="@drawable/your_image_here" /> 
</LinearLayout> 
+0

謝謝你的答案,但原諒我的無知。我知道在項目中包含splash.xml的位置,但我不確定其他代碼屬於哪裏。 – user3160965

+0

'splash.xml - >/layout', - >'SplashScreen.java'中的代碼,您必須創建一個文件。然後,你當然有艙單申報活動爲'<活動 \t \t \t機器人:名字= 「閃屏」 \t \t \t機器人:標籤= 「@字符串/ APP_NAME」/>' – 2011-08-08 16:26:06