Splash Screen Alpha Animation In Android
I want to display a splash screen animation where an image fades in and then fades out. I want the second activity to load after the image has faded out. Fade-in time (1000 ms) W
Solution 1:
You can do it using an AnimationSet. The Animation.setStartOffset()
method allows to say when the animation should start (0 for the fadeIn and 2000 for the fadeOut). The next Activity is launched after 3 seconds using a Handler.postDelayed()
.
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);
}
Post a Comment for "Splash Screen Alpha Animation In Android"