install android studio

Splash Screen Animation in Android

Splash Screen :

Splash screen is first  screen/window of the android app which is generally used in games and when any program is launched. Splash Screen is the introduction activity of the android app which consist logo, image or the current version of the android app.

Splash Screen may covers the entire screen and or  also take small portion of the screen . It delays the content for very small time span on the screen and immediately opens another activity.

Splash Screen animation:

Splash Animations are generally used in almost all splash screens to make it more effective and user friendly . Splash Animations includes many effects like left slide , right slide , up and down slide , fading , moving  and finally smooth switching to another activity.

For Splash Animations , we need to create anim directory in Android studio in which two XML files made. These XML files contain the animation effect for images and logos in Splash Screen .

implementation:

For implementation , we need to make few files for animation or other for java code and designing part. Just follow the steps :

1.Alpha.xml :

First XML file named as “alpha.xml” in my project which includes animation effects of time delay (duration) or opacity level (fromAlpha) to (toAlpha). Put below code in your alpha file.

<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="4000"
android:fromAlpha="0.0"
android:toAlpha="1.0" />

2. Translate.xml :

Second file named as translate.xml in my project which includes transitions , time dealy , from where to there .Put below code in your translate file.

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="3500"
android:zAdjustment="top" 
android:fromXDelta="200%" 
android:toXDelta="0%" 
android:fromYDelta="0%"
android:toYDelta="0%" />
</set>

3. SplashScreenActvity.java :


public class SplashScreen extends Activity {
public void onAttachedToWindow() {
super.onAttachedToWindow();
Window window = getWindow();
window.setFormat(PixelFormat.RGBA_8888);
}
/** Called when the activity is first created. */
Thread splashTread;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
StartAnimations();
}
private void StartAnimations() {
Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
anim.reset();
RelativeLayout l=(RelativeLayout) findViewById(R.id.relativeLayout);
l.clearAnimation();
l.startAnimation(anim);

anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
anim.reset();
ImageView iv = (ImageView) findViewById(R.id.splash);
iv.clearAnimation();
iv.startAnimation(anim);

anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
anim.reset();
TextView tv1 = (TextView) findViewById(R.id.text2016);
tv1.clearAnimation();
tv1.startAnimation(anim);

splashTread = new Thread() {
@Override
public void run() {
try {
int waited = 0;
// Splash screen pause time
while (waited < 3500) {
sleep(180);
waited += 100;
}
Intent intent = new Intent(SplashScreen.this,
MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
SplashScreen.this.finish();
} catch (InterruptedException e) {
// do nothing
} finally {
SplashScreen.this.finish();
}}};
splashTread.start();
}} 

4. Android Manifest file :

We need to made SplashScreenActivity as a launcher activity in Android Manifest file like


<activity android:name=".SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Problem (if any ) will be discussed in Comment section .

About the author

Generic Bytes

Hi! we are from Generic Bytes an aspiring bloggers with an obsession of things tech.This blog is dedicated to people who want to learn the technology.

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *