이것Do! 저것Do!!

1. logo로 사용할 이미지 준비

-> 간단하게 res/drawable-xxhdpi에 있는 ic_launcher.png를 복사하여 android_logo.png라는 이름으로 바꾸고 이것을 테스트할 폰에 맞는 디렉토리(drawable-xhdpi 혹은 drawable-hdpi)로 위치시켜 이것을 로고 애니메이션에 사용한다.


2. res/layout/activity_main.xml 편집

-> 원래 있던 TextView를 없애고 로고 이미지를 처리하기 위한 ImageView를 추가한다.

   1: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   2:     xmlns:tools="http://schemas.android.com/tools"
   3:     android:layout_width="match_parent"
   4:     android:layout_height="match_parent"
   5:     android:paddingBottom="@dimen/activity_vertical_margin"
   6:     android:paddingLeft="@dimen/activity_horizontal_margin"
   7:     android:paddingRight="@dimen/activity_horizontal_margin"
   8:     android:paddingTop="@dimen/activity_vertical_margin"
   9:     tools:context=".MainActivity" >
  10:     
  11:     <ImageView
  12:         android:id="@+id/imgLogo"
  13:         android:layout_width="wrap_content"
  14:         android:layout_height="wrap_content"
  15:         android:layout_centerHorizontal="true"
  16:         android:layout_centerVertical="true"
  17:         android:src="@drawable/android_logo" />
  18:  
  19: </RelativeLayout>


3. fade-out 효과를 주기 위한 xml 추가

-> res에 ‘anim’이란 디렉토리를 하나 추가하고 아래의 내용을 담고 있는 ‘splash.xml’를 만들어준다.

   1: <?xml version="1.0" encoding="UTF-8"?>
   2: <set xmlns:android="http://schemas.android.com/apk/res/android" >
   3:     <alpha
   4:         android:startOffset="1500"
   5:         android:duration="1000"
   6:         android:fromAlpha="1.0"
   7:         android:toAlpha="0.0"
   8:         android:interpolator="@android:anim/accelerate_interpolator"
   9:         android:repeatCount="0" />
  10: </set>


4. MainActivity에 AnimationListener를 구현

-> 이클립스에서 AnimationListener를 implements하겠다고 작성을 하면 구현해야 할 method들을 알아서 표시해 준다. 로고가 fade-out되면 다음 화면으로 넘어가도록 구현하면 되므로 onAnimationEnd()에 다음 activity로 전환되도록 구성해 본다.

   1: package com.example.abc;
   2:  
   3: import android.os.Bundle;
   4: import android.app.Activity;
   5: import android.content.Intent;
   6: import android.view.Menu;
   7: import android.view.View;
   8: import android.view.animation.Animation;
   9: import android.view.animation.AnimationUtils;
  10: import android.view.animation.Animation.AnimationListener;
  11:  
  12: public class MainActivity extends Activity implements AnimationListener{
  13:  
  14:     @Override
  15:     protected void onCreate(Bundle savedInstanceState) {
  16:         super.onCreate(savedInstanceState);
  17:         setContentView(R.layout.activity_main);
  18:         
  19:         Animation animation = AnimationUtils.loadAnimation(this, R.anim.splash);
  20:         animation.setAnimationListener(this);
  21:         findViewById(R.id.imgLogo).startAnimation(animation);
  22:     }
  23:  
  24:     @Override
  25:     public boolean onCreateOptionsMenu(Menu menu) {
  26:         // Inflate the menu; this adds items to the action bar if it is present.
  27:         getMenuInflater().inflate(R.menu.main, menu);
  28:         return true;
  29:     }
  30:  
  31:     @Override
  32:     public void onAnimationEnd(Animation animation) {
  33:         findViewById(R.id.imgLogo).setVisibility(View.INVISIBLE);
  34:         
  35:         Intent intent = new Intent(MainActivity.this, MenuActivity.class);
  36:         startActivity(intent);
  37:         finish();
  38:     }
  39:  
  40:     @Override
  41:     public void onAnimationRepeat(Animation animation) {
  42:         // TODO Auto-generated method stub
  43:         
  44:     }
  45:  
  46:     @Override
  47:     public void onAnimationStart(Animation animation) {
  48:         // TODO Auto-generated method stub
  49:         
  50:     }
  51:  
  52: }