로딩 화면(splash activity)을 만들고싶어요
조회수 13142회
1 답변
-
Splash Activity에 쓸 레이아웃을 만들어줍니다.
<?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/splashscreen" android:layout_width="wrap_content" android:layout_height="fill_parent" android:src="@drawable/splash" android:layout_gravity="center"/> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Hello World, splash"/> </LinearLayout>
그리고 Splash Activity를 만들어줍니다.
import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; public class Splash extends Activity { /** 로딩 화면이 떠있는 시간(밀리초단위) **/ private final int SPLASH_DISPLAY_LENGTH = 1000; /** 처음 액티비티가 생성될때 불려진다. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.splashscreen); /* SPLASH_DISPLAY_LENGTH 뒤에 메뉴 액티비티를 실행시키고 종료한다.*/ new Handler().postDelayed(new Runnable(){ @Override public void run() { /* 메뉴액티비티를 실행하고 로딩화면을 죽인다.*/ Intent mainIntent = new Intent(Splash.this,Menu.class); Splash.this.startActivity(mainIntent); Splash.this.finish(); } }, SPLASH_DISPLAY_LENGTH); } }
그리고 안드로이드 매니페스트 파일에가서 부분에 시작 액티비티를 Splash로 바꿔줍니다.
댓글 입력