android程序启动画面之Splash总结
2014-05-18 15:57
459 查看
方法一:
很多应用都会有一个启动界面。欢迎画面慢慢隐现,然后慢慢消隐。实现这种效果的方法有两种(暂时只发现两种)
1、使用两个Activity,程序启动时候load第一张Activity,然后由tick触发N秒钟后startActivity另外一张Activity。
2、使用一个Activity,可以用到View.gone() 这个方法。把Acitivity的某些元素移除。
1、两个Activity:
首先是AndroidManifest.xml
然后是JAVA代码:
当然可以再Splash中加入动画效果。(我觉得先要布局好AndroidManifest.xml。因为那才是工程的索引文件。首先在那要有一个统筹!而不是先写java code。然后逐步往xml中增加 ,这说明对整个项目没有一个统筹的设计)
方法二:
androidmanifest.xml就不多说了。先看布局代码:
有一个id为splashscreen 的linearlayout,是程序启动时显现的部分。id为browser是程序的主界面显示部分。
view
source
print?
很多应用都会有一个启动界面。欢迎画面慢慢隐现,然后慢慢消隐。实现这种效果的方法有两种(暂时只发现两种)
1、使用两个Activity,程序启动时候load第一张Activity,然后由tick触发N秒钟后startActivity另外一张Activity。
2、使用一个Activity,可以用到View.gone() 这个方法。把Acitivity的某些元素移除。
1、两个Activity:
首先是AndroidManifest.xml
01 | <? xml version = "1.0" encoding = "utf-8" ?> |
02 | < manifest xmlns:android = "http://schemas.android.com/apk/res/android" |
03 | package = "com.sunshine.splash" |
04 | android:versionCode = "1" |
05 | android:versionName = "1.0" > |
06 | <application android:icon = "@drawable/icon" ; android:label = "@string/app_name" > ; |
07 | < activity android:name = ".Splash" |
08 | android:label = "@string/app_name" > ; |
09 | < intent-filter > |
10 | < action android:name = "android.intent.action.MAIN" /> |
11 | < category android:name = "android.intent.category.LAUNCHER" /> |
12 | </ intent-filter > |
13 | </ activity > |
14 | < activity android:name = "Main" > |
15 | </ activity > |
16 | </ application > |
17 | < uses-sdk android:minSdkVersion = "3" /> |
18 | </ manifest > |
01 | package net.hlovey.splash; |
02 | import android.app.Activity; |
03 | import android.content.Intent; |
04 | import android.os.Bundle; |
05 | import android.os.Handler; |
06 |
07 | public class Splash extends Activity { |
08 |
09 | private final int SPLASH_DISPLAY_LENGHT = 3000 ; //延迟三秒 |
10 |
11 | @Override |
12 | public void onCreate(Bundle savedInstanceState) { |
13 | super .onCreate(savedInstanceState); |
14 | setContentView(R.layout.splash); |
15 | new Handler().postDelayed( new Runnable(){ |
16 |
17 | @Override |
18 | public void run() { |
19 | Intent mainIntent = new Intent(Splash. this ,Main. class ); |
20 | Splash. this .startActivity(mainIntent); |
21 | Splash. this .finish(); |
22 | } |
23 |
24 | }, SPLASH_DISPLAY_LENGHT); |
25 | } |
26 | } |
方法二:
androidmanifest.xml就不多说了。先看布局代码:
01 | <? xml version=”1.0″ encoding=”utf-8″?> |
02 | < LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” |
03 | android:orientation=”vertical” |
04 | android:layout_width=”fill_parent” |
05 | android:layout_height=”fill_parent”> |
06 | < LinearLayout android:id=”@+id/splashscreen” android:orientation=”vertical” |
07 | android:layout_width=”fill_parent” android:layout_height=”fill_parent”> |
08 | < ImageView android:layout_width=”wrap_content” |
09 | android:layout_height=”wrap_content” android:src=”@drawable/splash” |
10 | android:layout_gravity=”center” |
11 | android:layout_marginTop=”130px”/> |
12 | < TextView |
13 | android:id=”@+id/info” |
14 | android:layout_width=”fill_parent” |
15 | android:layout_height=”wrap_content” |
16 | android:gravity=”center” |
17 | android:paddingTop=”10px” |
18 | android:text=”This is a splash!!”/> |
19 | </ LinearLayout > |
20 | < WebView android:id=”@+id/browser” |
21 | android:layout_width=”fill_parent” |
22 | android:layout_height=”fill_parent” android:layout_weight=”1″/> |
23 | </ LinearLayout > |
view
source
print?
01 | package net.hlovey.s; |
02 | import android.app.Activity; |
03 | import android.app.AlertDialog; |
04 | import android.content.DialogInterface; |
05 | import android.content.Intent; |
06 | import android.os.Bundle; |
07 | import android.os.Handler; |
08 | import android.os.Message; |
09 | import android.util.Log; |
10 | import android.view.LayoutInflater; |
11 | import android.view.animation.Animation; |
12 | import android.view.animation.AnimationUtils; |
13 | import android.widget.LinearLayout; |
14 | import android.widget.TextView; |
15 | import android.widget.Toast; |
16 | public class WebGameActivity extends Activity { |
17 |
18 | private WebView webView; |
19 |
20 | private Handler mHandler = new Handler(); |
21 |
22 | private static final String TAG = "WebGameActivity" ; |
23 | //菜单 |
24 | private static final int MENU_RELOAD = Menu.FIRST; |
25 | private static final int MENU_HELP 1 ; |
26 | private static final int MENU_ABOUT 2 ; |
27 | private static final int MENU_CLOSE 3 ; |
28 | private int staus = 0 ; |
29 |
30 | private static final int STOPSPLASH = 0 ; |
31 | //time in milliseconds |
32 | private static final long SPLASHTIME = 1000 ; |
33 |
34 | private LinearLayout splash; |
35 | private TextView tv; |
36 |
37 | private Animation myAnimation_Alpha; |
38 | private Animation animatinoGone ; |
39 |
40 | private Handler splashHandler = new Handler() { |
41 | public void handleMessage(Message msg) { |
42 | switch (msg.what) { |
43 | case STOPSPLASH: |
44 | if ( staus == 1 ){ |
45 | splash.startAnimation(animatinoGone); |
46 | splash.setVisibility(View.GONE); |
47 | break ; |
48 | } |
49 | sendEmptyMessageDelayed(STOPSPLASH, SPLASHTIME); |
50 | } |
51 | super .handleMessage(msg); |
52 | } |
53 | }; |
54 |
55 | @Override |
56 | protected void onCreate(Bundle savedInstanceState) { |
57 | super .onCreate(savedInstanceState); |
58 | getWindow().requestFeature(Window.FEATURE_PROGRESS); //去标题栏 |
59 | setContentView(R.layout.main); |
60 | animatinoGone = AnimationUtils.loadAnimation( this ,R.anim.alpha_gone); //动画效果 |
61 | myAnimation_Alpha = AnimationUtils.loadAnimation( this ,R.anim.alpha_action); //动画效果 |
62 |
63 | splash = (LinearLayout) findViewById(R.id.splashscreen); |
64 | tv = (TextView) findViewById(R.id.info); |
65 | tv.setText( "正在建立数据连接" ); |
66 | splash.startAnimation(myAnimation_Alpha); |
67 |
68 | Message msg = new Message(); |
69 | msg.what = STOPSPLASH; |
70 | splashHandler.sendMessageDelayed(msg, SPLASHTIME); |
71 |
72 | } |
相关文章推荐
- 鉴客 android程序启动画面之Splash总结
- android程序启动画面之Splash总结
- android程序启动画面之Splash总结
- android程序启动画面之Splash总结
- android程序启动画面之Splash总结
- android程序启动画面之Splash总结
- android程序启动画面之Splash总结
- android程序启动画面之Splash总结
- android程序启动画面之Splash总结
- android程序启动画面之Splash总结
- android程序启动画面之Splash总结
- android程序启动画面之Splash总结
- Android程序启动画面之Splash总结
- android程序启动画面之Splash总结
- android程序启动画面之Splash总结[转]
- android程序启动画面之Splash总结
- android程序启动画面之Splash总结
- android程序启动画面之Splash总结
- Android程序启动画面之Splash
- Android -- 程序启动画面 Splash