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"> <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; // three seconds delayed @ 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.
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 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. alpha_gone); // animation effect
MyAnimation_Alpha = AnimationUtils. loadAnimation (this, R. anim. alpha_action); // 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 );
}