You are on page 1of 3

Android Fancy Animated

Splash Screen
03/24/2012, Munish Kapoor, 5 Comments

In this tutorial you will learn how to create the animation splash screen in android. I have used
the translate and alpha animation.
Step 1-> create the anim folder on android resources folder and create the android xml file
(anim/alpha.xml) as following
1
<?xml version="1.0" encoding="utf-8"?>
2
<alpha
xmlns:android="http://schemas.android.com/apk/res/android"
3
android:fromAlpha="0.0"
4
android:toAlpha="1.0"
5
android:duration="3000" />
6
Step 2-> create the android xml file under anim folder (anim/translate.xml) as following
1
<?xml version="1.0" encoding="utf-8"?>
2
<set
3
xmlns:android="http://schemas.android.com/apk/res/android">
4
5
<translate
6
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0%"
7
android:toXDelta="0%"
8
android:fromYDelta="200%"
9
android:toYDelta="0%"
10
android:duration="2000"
11
android:zAdjustment="top" />
12
</set>
13
14
Step 3-> main.xml file
1
2
3
4
5
6
7
8

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/radialback"
android:layout_gravity="center"
android:id="@+id/lin_lay"
android:gravity="center"
android:orientation="vertical" >

9
10
<ImageView
11
android:layout_width="wrap_content"
android:layout_height="wrap_content"
12
android:id="@+id/logo"
13
android:background="@drawable/logo" />
14
15
</LinearLayout>
16
17
Step 4-> SpalshScreenActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

package com.fancy.splashscreen;
import
import
import
import
import
import
import
import

android.app.Activity;
android.graphics.PixelFormat;
android.os.Bundle;
android.view.Window;
android.view.animation.Animation;
android.view.animation.AnimationUtils;
android.widget.ImageView;
android.widget.LinearLayout;

public class SpalshScreenActivity extends Activity {


public void onAttachedToWindow() {
super.onAttachedToWindow();
Window window = getWindow();
window.setFormat(PixelFormat.RGBA_8888);
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
StartAnimations();
}
private void StartAnimations() {
Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
anim.reset();
LinearLayout l=(LinearLayout) findViewById(R.id.lin_lay);
l.clearAnimation();
l.startAnimation(anim);
anim = AnimationUtils.loadAnimation(this, R.anim.translate);
anim.reset();
ImageView iv = (ImageView) findViewById(R.id.logo);
iv.clearAnimation();
iv.startAnimation(anim);
}
}

36
37
38
39
40

You might also like