Hello world. Today i wanna show how to create slash screen with animation in android apps. In this post i am use small to big to small animation, you can see in demo apps. I am using last android studio and lollipop minimum sdk. lest do this.
First important thing if you want to make splash screen is logo, this is important for you and make your logo to png file, cause it can be our android apps runs fast. Splash screen its a activity so we make first activity for splash screen. This is important code in screen activity.
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
finish();
}
}, SPLASH_TIME_OUT);
So the purpose for this function is before we move to another activity (main activity class), the screen activity will hold until splash_time_out done. splash_time_out is integer variable. In this case i set 3000 it mean 3 second. Yup its purpose we make hander in splash screen activity.
Whats about xml layout? in xml layout i just put image and text, and image and text i will make animation. Actually this layout is similar with another layout, you can see in the my demo code.
The second thing i wanna make animation in the splash screen. So this is my important code in splash screen activity.
protected void onResume() {
super.onResume();
logo_holder.startAnimation(anim_logo);
Handler handler = new Handler();
Runnable startMain = new Runnable() {
@Override
public void run() {
if (!isFinishing()){
text_holder.startAnimation(anim_txt);
}
}
};
handler.postDelayed(startMain, 200);
}
The purpose onResume function is make logo_holder to start animation (anim_logo is code xml i put in the anim folder on res) and then after image done for the animation, text will be show after image done, see in condition (if finishing).
You can download my source code bellow, after this you can see my code and understand it, if you still confuse about code, you can write comment bellow. Thanks.
Source Code Github
