프로그래밍/Android

Splash window 보이기

chance 2009. 11. 24. 15:00

1. 레이아웃 작성

res/layout/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:id="@+id/spalsh_image"

android:layout_width = "wrap_content"

android:layout_height = "fill_parent"

android:layout_gravity="center"

android:scaleType="fitCenter"

android:src="@drawable/splash_image"

/>

<TextView ... /> 

</LinearLayout>

 

2. 엑티비티 구성 : 별거읍다.. 이미지 보이고, 원하는 시간 지난 후 다른 액티비티

호출해주면 끝.

 

private ImageView splash;

 

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R,layout.splash);

 

splash = (ImageView) findViewById(R.id.splash);

Handle handle = new Handle();

handle.postDelayed( new Runnable() {

@Override

public void run() {

// start other activity

Intent main = new Intent(ThisActivity.this, NewActivity.class );

ThisActivity.this.startActivity(main);

ThisActivity.this.finish();

}

} , 1000 );

}

요러면 일단 이미지가 나왔다가 원하는 액티비티가 실행된다.

헌데, 당연 영~ 맘에 안들수도~ 

 

 

 

요기부터는 스플래시 화면을 좀 꾸벼보자는 의도~

 

3. 에니메이션 추가하기 : Animation 객체로 페이드인 기능을 넣어본다~

뷰 에니메이션이 추가되므로 리스너 등록.

 

@Override

public void onCreate(Bundle icicle) {

super.onCreate(icicle);

setContentView(R,layout.splash);

 

Animation animation = new AlphaAnimation( 0.0f, 1.0f );

animation.setAnimationListener(new AnimationListener() {

@Override

public void onAnimationEnd(Animation arg0) {

 // TODO Auto-generated method stub

Handler handler = new Handler();

handler.postDelayed( new Runnable() {

@Override

public void run() {

// TODO Auto-generated method stub

Intent intent = new Intent(SplashScreen.this, ???.class);

startActivity(intent);

SplashScreen.this.finish();

}

}, 3000 );

}

});

animation.setDuration(2000);

splash = (ImageView) findViewById(R.id.splash);

splash.startAnimation( animation );

 

}

요렇게 하면 2초간 페이드인 에니메이션이 일어나고, 에니메이션 종료 후 3초있다가

???.class 로 이동하게 된다.

이 방법외에 activity 전환 에니메이션을 걸어줘도 된다.

 

4. 투명 레이아웃 적용하기

 

스플래쉬 윈도는 배경없이 원하는 이미지만 샥~ 하고 떠야 제맛!!!!

그래서, 배경을 날려본다. 

가장 간단한 방법은 엑티비티에 안드로이드 테마를 적용하는 것이다.

 

manifest.xml 파일을 열어보면 각 엑티비티가 선언되어 있을텐데

그중 스플래시 액티비트를 아래와 같이 변경한다.

<activity android:name=".SplashActivity"

.

.

android:theme="@android:style/Theme.Translucent"

.

.

</activity>

 

다시 실행해 보면 배경이 투명해진것을 확인 할 수 있다. 하지만, 문제는 역시나 하나 존재하는데~

바로 타이틀바~

요건 스타일로 정의해놓고 적용~

 

 <style name="Theme.Translucent"  parent="android:style/Theme.Translucent">

  <item name="android:windowBackground">@android:color/transparent</item>

  <item name="android:windowNoTitle">true</item> 

  <item name="android:foregroundColor">#fff</item> 

 </style>

 

 

 

android:theme="@style/Theme.Translucent"

 

아니면 액티비티 onCreate시에

requestWindowFeature(Window.FEATURE_NO_TITLE);

 

끗!!!