當(dāng)前位置:
首頁 >
【Android】android开发之splash闪屏页的四种实现方式,启动页的实现教程。
發(fā)布時間:2025/3/20
43
豆豆
生活随笔
收集整理的這篇文章主要介紹了
【Android】android开发之splash闪屏页的四种实现方式,启动页的实现教程。
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
2019獨角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
作者:程序員小冰,GitHub主頁: https://github.com/QQ986945193 ?新浪微博:http://weibo.com/mcxiaobing?
首先給大家看一下今天實現(xiàn)的效果圖(其他三種都差不太多底下詳細(xì)介紹):
這個啟動頁實現(xiàn)的方法是四種,兩種是利用handler,其它兩種是利用了動畫的方式。
具體給大家貼一下源代碼吧,很簡單。
布局文件就一個圖片,mainfest添加上我們的類就行了。
java實現(xiàn)代碼如下:
package xiaobingsplashmoremethod.qq986945193.xiaobingsplashmoremethod.xiaobingsplashmoremethod;import android.annotation.SuppressLint; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.animation.AnimationSet; import android.view.animation.RotateAnimation; import android.view.animation.ScaleAnimation; import android.widget.LinearLayout;/*** @author :程序員小冰* @新浪微博 :http://weibo.com/mcxiaobing* @GitHub:https://github.com/QQ986945193* @CSDN博客: http://blog.csdn.net/qq_21376985* @交流Qq :986945193* 類名:splash閃屏頁的四種實現(xiàn)方式*/ public class SplashActivity extends Activity {private LinearLayout ll_splash;private Handler mHandler = new Handler() {@Overridepublic void handleMessage(Message msg) {super.handleMessage(msg);switch (msg.what) {case 1:startMainActivity();break;case 2:startMainActivity();break;}}};@SuppressLint("WrongViewCast")@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_splash);ll_splash = (LinearLayout) findViewById(R.id.ll_splash);/*** 第一種方法,利用handler自帶的sendEmptyMessageDelayed()方法。*/mHandler.sendEmptyMessageDelayed(1, 2000);/*** 第二種方法,其實實現(xiàn)原理和第一種是一樣的,*/ // // Message message = new Message(); // message.what = 2; // mHandler.sendMessageDelayed(message, 2000);/*** 第三種方法,利用動畫實現(xiàn)*/ // startAdimThree();/*** 第四種方法,利用動畫實現(xiàn)*/ // StartAniFour();}private void StartAniFour() {AlphaAnimation start = new AlphaAnimation(0.0f, 1.0f);start.setDuration(1000);// findViewById(R.id.splash).startAnimation(start);start.setAnimationListener(new Animation.AnimationListener() {@Overridepublic void onAnimationStart(Animation animation) {}@Overridepublic void onAnimationEnd(Animation animation) {startMainActivity();}@Overridepublic void onAnimationRepeat(Animation animation) {}});ll_splash.startAnimation(start);}/*** 開啟動畫*/private void startAdimThree() {// 動畫集合AnimationSet set = new AnimationSet(false);// 旋轉(zhuǎn)動畫RotateAnimation rotateAnimation = new RotateAnimation(180, 180,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,0.5f);rotateAnimation.setDuration(2000);// 設(shè)置動畫時間rotateAnimation.setFillAfter(true);// 保持動畫狀態(tài)// 縮放動畫ScaleAnimation scaleAnimation = new ScaleAnimation(0, 1, 0, 1,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,0.5f);scaleAnimation.setDuration(2000);// 設(shè)置動畫時間scaleAnimation.setFillAfter(true);// 保持動畫狀態(tài)// 漸變動畫AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);alphaAnimation.setDuration(2000);alphaAnimation.setFillAfter(true);// 保持動畫狀態(tài)// 添加動畫set.addAnimation(rotateAnimation);set.addAnimation(scaleAnimation);set.addAnimation(alphaAnimation);/** 設(shè)置動畫的監(jiān)聽事件,當(dāng)動畫運行完成后,啟動新的activity*/set.setAnimationListener(new Animation.AnimationListener() {@Overridepublic void onAnimationStart(Animation animation) {// TODO Auto-generated method stub}@Overridepublic void onAnimationRepeat(Animation animation) {// TODO Auto-generated method stub}@Overridepublic void onAnimationEnd(Animation animation) {// TODO Auto-generated method stubstartMainActivity();}});ll_splash.startAnimation(set);}/*** 跳轉(zhuǎn)到主界面*/private void startMainActivity() {startActivity(new Intent(SplashActivity.this, MainActivity.class));finish();}@Overrideprotected void onDestroy() {super.onDestroy(); // mHandler.removeMessages(1); // mHandler.removeMessages(2);} } (AndroidStudio版)github下載地址:?
https://github.com/QQ986945193/XiaoBingSplashMoreMethod
轉(zhuǎn)載于:https://my.oschina.net/mcxiaobing/blog/776985
總結(jié)
以上是生活随笔為你收集整理的【Android】android开发之splash闪屏页的四种实现方式,启动页的实现教程。的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 修改oracle数据库密码
- 下一篇: Racket 6.7最新版本:提供对An