Method One:
Many applications will have a startup interface. Welcome to the screen slowly looming, and then slowly fade away. There are two ways to achieve this effect (only two are found temporarily)
1, the use of two activity, the program starts load the first activity, and then triggered by tick n seconds after startactivity another activity.
2, the use of an activity, you can use the View.gone () this method. Remove some elements from the acitivity.
1. Two activity:
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 ">
<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 three seconds
@Override
publi c 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 animation effect in Splash. (I think we need to lay out the androidmanifest.xml first.) Because that's the index file for the project. First of all, there should be a co-ordination! Instead of writing Java code first. And then incrementally add to the XML, which shows that there is no integrated design for the entire project.
Method Two:
Androidmanifest.xml will not say much more. 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_w Idth= "Wrap_content" android:layout_height= "wrap_content" android:src= "@drawable/splash" Andr oid:layout_gravity= "center" android:layout_margintop= "130px"/> <textview and
Roid:id= "@+id/info" android:layout_width= "fill_parent" android:layout_height= "Wrap_content" android:gravity= "center" android:paddingtop= "10px" android:text= "This is a SP lash!! " /> </LinearLayout> < WebView android:id= "@+id/browser" android:layout_width= "fill_parent" android:layout_height= "Fill_parent" Android: layout_weight= "1″/> </linearlayout>
A linearlayout with an ID of SplashScreen is the part that appears when the program starts. ID browser is the main interface display part of the program.
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 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 splashtime = 1000;
Private LinearLayout Splash;
Private TextView TV;
Private Animation Myanimation_alpha;
Private Animation Animatinogone;
Private Handler Splashhandler = new Handler () {
public void Handlemessage (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.alpha_gone); Animation effects
Myanimation_alpha = Animationutils.loadanimation (this,r.anim.alpha_action); Animation effects
Splash = (linearlayout) Findviewbyid (R.id.splashscreen);
TV = (TextView) Findviewbyid (r.id.info);
Tv.settext ("Data connection is being established");
Splash.startanimation (Myanimation_alpha);
msg = new Message ();
Msg.what = Stopsplash;
Splashhandler.sendmessagedelayed (msg, splashtime);
}