로딩 화면(splash activity)을 만들고싶어요

조회수 13190회

앱을 좀더 있어보이게 만들고싶어서 고민하다 로딩화면 같은걸 넣으려고 하는데요. 어떻게 하면 로딩화면을 만들수 있을까요?

1 답변

  • 좋아요

    0

    싫어요
    채택 취소하기

    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로 바꿔줍니다.

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)