Splash Screen In Android

Description:
This is a implementation of a simple splash screen with animation In Android. It will show a image on start and removes it after a specific time:

Following Step Given Below.

1. main.xml

<com.devappandroid.splash.SplasGraphics
android:id=”@+id/graphics”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”/>


2. SplashGraphics.java

In this file we have to create window service.

public SplasGraphics(Context context)
{
super(context);
display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
init();
}

public SplasGraphics(Context context, AttributeSet attrs)
{
super(context, attrs);
display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
init();
}

Then  put image on drawable folder.

private void init()
{
this.setFocusableInTouchMode(true);
this.setFocusable(true);
p = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
}

@Override
protected void onDraw(Canvas canvas)
{
canvas.drawBitmap(p, 0, 0, null);
}

Now we have to create another java file.

3. splash.java

private AnimationSet getAnimation() {
rootSet = new AnimationSet(true);
rootSet.setInterpolator(new BounceInterpolator());

TranslateAnimation trans1 = new TranslateAnimation(0, 0, -400, 0);
trans1.setStartOffset(0);
trans1.setDuration(800);
trans1.setFillAfter(true);
rootSet.addAnimation(trans1);

ScaleAnimation scale = new ScaleAnimation(0, 1, 0, 1,
ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
scale.setDuration(800);
scale.setFillAfter(true);
AnimationSet childSet = new AnimationSet(true);
childSet.addAnimation(scale);
childSet.setInterpolator(new BounceInterpolator());
rootSet.addAnimation(childSet);

Animation outtoRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, +1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
outtoRight.setStartOffset(4000);
outtoRight.setDuration(400);
outtoRight.setInterpolator(new AccelerateInterpolator());
rootSet.addAnimation(outtoRight);

return rootSet;
}

That’s it..

{filelink=3}