2012-07-12 7 views
2

이미지가 희미 해지고 사라지는 스플래시 화면 애니메이션을 표시하고 싶습니다. 이미지가 희미 해지면 두 번째 활동을로드하고 싶습니다.스플래시 화면 안드로이드의 알파 애니메이션

  1. 페이드 타임 (1000 MS)
  2. 기다림 (1000 MS)
  3. 페이드 아웃 시간 (1000 MS)
  4. 기다림 (1000 MS)
  5. 로드 초 활동

어떻게해야합니까? 현재 사용중인 코드는 다음과 같습니다.

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.animation.AccelerateInterpolator; 
import android.view.animation.AlphaAnimation; 
import android.view.animation.Animation; 
import android.widget.ImageView; 
public class Splash extends Activity 
{ 
    ImageView img; 
    Thread timer; 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.splash); 
     img = (ImageView) findViewById (R.id.imgSplash); 
     img.startAnimation(FadeIn(1000)); 
     try 
     { 
      Thread.sleep(1000); 
     } 
     catch (InterruptedException e1) 
     { 
      e1.printStackTrace(); 
     } 

     img.startAnimation(FadeOut(1000)); 

     try 
     { 
      Thread.sleep(1000); 
     } 
     catch (InterruptedException e1) 
     { 
      e1.printStackTrace(); 
     } 
     timer.start(); 
     Intent intent = new Intent(); 
     intent.setClass(Splash.this,MainScreen.class); 
     startActivity(intent); 
    } 
    public void onPause() 
    { 
     super.onPause(); 
     finish(); 
    } 
    private Animation FadeIn(int t) 
    { 
     Animation fade; 
     fade = new AlphaAnimation(0.0f,1.0f); 
     fade.setDuration(t); 
     fade.setInterpolator(new AccelerateInterpolator()); 
     return fade; 
    } 
    private Animation FadeOut(int t) 
    { 
     Animation fade; 
     fade = new AlphaAnimation(1.0f,0.0f); 
     fade.setDuration(t); 
     fade.setInterpolator(new AccelerateInterpolator()); 
     return fade; 
    } 
} 

도와주세요.

+1

두 번째 활동이 시작되지 않습니까? 아니면 시작될 것이라고 확인 하시겠습니까? – Addison

+0

1) 타이머가 초기화되지 않습니다. – fiddler

+2

사용자가 응용 프로그램을 사용할 때마다 4 초 동안 불필요하게 기다리지 않도록하십시오. 이렇게함으로써 당신은 그들의 시간을 낭비하고 있습니다 (그것은 그들을 귀찮게 할 것입니다). 활동을 시작하기 전에로드해야 할 것이 있다면 적재 중에 ​​스플래시를 보여주십시오. 응용 프로그램에 도착하기 전에 임의의 지연 시간을 추가하여 시간을 낭비하는 것입니다. [이 기사를보십시오] (http://blog.iangclifton.com/2011/01/01/android-splash-screens-done-right/). 어떻게 제대로하는지 알려줄 것입니다. – FoamyGuy

답변

3

AnimationSet을 사용하여 수행 할 수 있습니다. Animation.setStartOffset() 메서드를 사용하면 애니메이션이 시작될시기를 말할 수 있습니다 (fadeIn의 경우 0, fadeOut의 경우 2000). 다음 활동은 Handler.postDelayed()을 사용하여 3 초 후에 실행됩니다.

private final Handler handler = new Handler(); 

private final Runnable startActivityRunnable = new Runnable() { 

    @Override 
    public void run() { 
     Intent intent = new Intent(); 
      intent.setClass(Splash.this,MainScreen.class); 
     startActivity(intent); 
    } 
}; 

public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.splash); 
    img = (ImageView) findViewById (R.id.imgSplash); 

    setContentView(img); 
} 

@Override 
protected void onResume() { 
    super.onResume(); 

    AnimationSet set = new AnimationSet(true); 

    Animation fadeIn = FadeIn(1000); 
    fadeIn.setStartOffset(0); 
    set.addAnimation(fadeIn); 

    Animation fadeOut = FadeOut(1000); 
    fadeOut.setStartOffset(2000); 
    set.addAnimation(fadeOut); 

    img.startAnimation(set); 

    handler.postDelayed(startActivityRunnable, 3000); 
} 

public void onPause() 
{ 
    super.onPause(); 
    handler.removeCallbacks(startActivityRunnable); 
} 
+0

복사/붙여 넣기에 실수 한 것뿐입니다 ... 해결했습니다. 감사합니다 – fiddler

+0

이 새로운 버전은 어떻습니까? '뒤로'문제는 해결되어야합니다. 맞습니까? – fiddler

+0

예, 그렇게해야합니다. 배경 작업이 없다면 여전히 스플래시 화면을 사용하지 않는 것이 좋습니다. – FoamyGuy