Summary of Android app startup screen splash

Source: Internet
Author: User
Tags time in milliseconds

Method 1:

Many applications have a startup interface. You are welcome to gradually hide the image. There are two methods to achieve this effect (only two methods are found at the moment)
1. When two activities are used, load the first activity when the program starts, and then call tick to trigger another activity after n seconds.
2. You can use the view. Gone () method to use an activity. Removes some elements of acitivity.

1. Two activities:
First, androidmanifest. xml

<? XML version = "1.0" encoding = "UTF-8"?>
<Manifest xmlns: Android = "http://schemas.android.com/apk/res/android"
Package = "com. Sunshine. Splash"
Android: versioncode = "1"
Android: versionname = "1.0" & gt;
<Application Android: icon = "@ drawable/icon" Android: Label = "@ string/app_name">
<Activity Android: Name = ". Splash"
Android: Label = "@ string/app_name">
<Intent-filter>
<Action Android: Name = "android. Intent. Action. Main"/>
<Category Android: Name = "android. Intent. Category. launcher"/>
</Intent-filter>
</Activity>
<Activity Android: Name = "Main">
</Activity>
</Application>
<Uses-SDK Android: minsdkversion = "3"/>
</Manifest>

Then the Java code:

Package net. hlovey. Splash;
Import Android. App. activity;
Import Android. content. intent;
Import Android. OS. Bundle;
Import Android. OS. Handler;

Public class splash extends activity {

Private Final int splash_display_lenght = 3000; // delay of three seconds

@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Splash );
New handler (). postdelayed (New runnable (){

@ Override
Public void run (){
Intent mainintent = new intent (Splash. This, Main. Class );
Splash. This. startactivity (mainintent );
Splash. This. Finish ();
}

}, Splash_display_lenght );
}
}

Of course, you can add an animated effect to splash. (I think we must layout androidmanifest. xml first. Because that is the index file of the project. First, we need to have an overall plan! Instead of writing Java code first. And then add it to XML, which means there is no overall design for the entire project)

Method 2:

Androidmanifest. XML is not much to say. First look at the layout code:

<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: Orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
<Linearlayout Android: Id = "@ + ID/splashscreen" Android: Orientation = "vertical"
Android: layout_width = "fill_parent" Android: layout_height = "fill_parent">
<Imageview Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content" Android: src = "@ drawable/Splash"
Android: layout_gravity = "center"
Android: layout_margintop = "130px"/>
<Textview
Android: Id = "@ + ID/INFO"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: gravity = "center"
Android: paddingtop = "10px"
Android: text = "This is a splash !!" />
</Linearlayout>
<Webview Android: Id = "@ + ID/Browser"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent" Android: layout_weight = "1"/>
</Linearlayout>

There is a linearlayout with the ID of splashscreen, which is the part displayed when the program starts. Browser is the main interface display part of the program.

The loading_exit.xml file is as follows:

<? XML version = "1.0" encoding = "UTF-8"?>
<Set xmlns: Android = "http://schemas.android.com/apk/res/android">
<Alpha
Android: fromalphi = "1.0"
Android: toalpha = "0.1"
Android: duration= "250"
/>

</Set>

The loading_enter file is as follows:

<? XML version = "1.0" encoding = "UTF-8"?>
<Set xmlns: Android = "http://schemas.android.com/apk/res/android">
<Alpha
Android: fromalphi = "0.1"
Android: toalpha = "1.0"
Android: duration= "250"
/>
</Set>

For specific attribute settings, refer to: http://blog.csdn.net/hgl868/article/details/6711111

Package net. hlovey. S;
Import Android. App. activity;
Import Android. App. alertdialog;
Import Android. content. dialoginterface;
Import Android. content. intent;
Import Android. OS. Bundle;
Import Android. OS. Handler;
Import Android. OS. message;
Import Android. util. log;
Import Android. View. layoutinflater;
Import Android. View. animation. animation;
Import Android. View. animation. animationutils;
Import Android. widget. linearlayout;
Import Android. widget. textview;
Import Android. widget. Toast;
Public class webgameactivity extends activity {

Private webview;

Private handler mhandler = new handler ();

Private Static final string tag = "webgameactivity ";
// Menu
Private Static final int menu_reload = menu. first;
Private Static final int menu_help = menu. First + 1;
Private Static final int menu_about = menu. First + 2;
Private Static final int menu_close = menu. First + 3;
Private int staus = 0;

Private Static final int stopsplash = 0;
// Time in milliseconds
Private Static final long maid = 1000;

Private linearlayout Splash;
Private textview TV;

Private animation myanimation_alpha;
Private animation animatinogone;

Private handler splashhandler = new handler (){
Public void handlemessage (Message MSG ){
Switch (msg. What ){
Case stopsplash:
If (staus = 1 ){
Splash. startanimation (animatinogone );
Splash. setvisibility (view. Gone );
Break;
}
Sendemptymessagedelayed (stopsplash, splashtime );
}
Super. handlemessage (MSG );
}
};

@ Override
Protected void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Getwindow (). requestfeature (window. feature_progress); // go to the title bar
Setcontentview (R. layout. Main );
Animatinogone = animationutils. loadanimation (this, R. anim. loading_exit); // animation effect
Myanimation_alpha = animationutils. loadanimation (this, R. anim. loading_enter); // animation effect

Splash = (linearlayout) findviewbyid (R. Id. splashscreen );
TV = (textview) findviewbyid (r.id.info );
TV. settext ("establishing data connection ");
Splash. startanimation (myanimation_alpha );

Message MSG = new message ();
MSG. What = stopsplash;
Splashhandler. sendmessagedelayed (MSG, splashtime );

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.