每個應用程序都會有閃屏頁面的,那么接下來就看看閃屏頁面是如何實現的?
效果圖:
demo框架如下:
1、閃屏的布局如下:其實就是一張背景圖
1
2
3
4
5
6
7
|
<? xml version = "1.0" encoding = "utf-8" ?> < LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android" android:layout_width = "match_parent" android:layout_height = "match_parent" android:background = "@drawable/bg_app" android:orientation = "vertical" > </ LinearLayout > |
2、WelcomeActivity.java的代碼如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
package com.example.bamboo_splash; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; public class WelcomeActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_welcome); /** 方式一*/ // AlphaAnimation animation=new AlphaAnimation(0.3f, 1f); // animation.setDuration(3000); // animation.setAnimationListener(new AnimationListener() { // // @Override // public void onAnimationStart(Animation animation) { // // } // // @Override // public void onAnimationRepeat(Animation animation) { // // } // /** 動畫結束執行的方法*/ // @Override // public void onAnimationEnd(Animation animation) { // redirectTo(); // } // }); /** 方式二*/ new Handler().postDelayed( new Runnable() { @Override public void run() { redirectTo(); } }, 3000 ); } /** * 即將跳轉的頁面 */ public void redirectTo(){ Intent intent= new Intent(WelcomeActivity. this , MainActivity. class ); startActivity(intent); finish(); } } |
這樣一個簡單的閃屏效果就實現了呢,而且閃屏效果的實現有很多都方式,思路就是讓你開始的節面等待個幾秒鐘,然后顯示。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:https://blog.csdn.net/bzy601638015/article/details/30259403