Android中閃屏實(shí)現(xiàn)方法小結(jié)(普通閃屏、倒計(jì)時(shí)閃屏、倒計(jì)時(shí)+動(dòng)畫(huà)閃屏)
一、項(xiàng)目目錄結(jié)構(gòu)
二、activity_main.xml代碼
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.zgs.SplashScreenByXml.MainActivity" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="主頁(yè)面" /> </RelativeLayout>
三、activity_splashscreen.xml代碼
<?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/splash" android:orientation="vertical" android:id="@+id/ll_splashActivity"> <TextView android:id="@+id/tv_countDown" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end" android:layout_marginEnd="20dp" android:layout_marginTop="20dp" android:textColor="@android:color/white" android:textSize="20sp" /> </LinearLayout>
四、SplashScreenActiviy.java代碼
package com.zgs.SplashScreenByXml; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.CountDownTimer; import android.os.Handler; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.TranslateAnimation; import android.widget.LinearLayout; import android.widget.TextView; import com.zgs.CommonlySplashScreen.R; public class SplashScreenActiviy extends Activity { private TextView tv_countDown; private LinearLayout ll_splashActivity; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 通過(guò)下面兩行代碼也可實(shí)現(xiàn)全屏無(wú)標(biāo)題欄顯示activity // getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_splashscreen); tv_countDown = (TextView) findViewById(R.id.tv_countDown); ll_splashActivity = (LinearLayout) findViewById(R.id.ll_splashActivity); /******************************************************************************** * * 普通閃屏實(shí)現(xiàn)方式 * * ******************************************************************************/ /*new Handler().postDelayed(new Runnable() { @Override public void run() { Intent intent = new Intent(getApplicationContext(), MainActivity.class); startActivity(intent); finish(); } }, 1000*4);*/ /******************************************************************************** * * 倒計(jì)時(shí)閃屏實(shí)現(xiàn)方式 * * ******************************************************************************/ /*MyCountDownTimer mc = new MyCountDownTimer(4000, 1000); mc.start(); new Handler().postDelayed(new Runnable() { @Override public void run() { Intent intent = new Intent(getApplicationContext(), MainActivity.class); startActivity(intent); finish(); } }, 1000*4);*/ /******************************************************************************** * * 倒計(jì)時(shí)+動(dòng)畫(huà)閃屏實(shí)現(xiàn)方式 * * ******************************************************************************/ MyCountDownTimer mc = new MyCountDownTimer(4000, 1000); mc.start(); new Handler().postDelayed(new Runnable() { @Override public void run() { //左移動(dòng)畫(huà) TranslateAnimation ta = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, -1, Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0); ta.setDuration(2000); //設(shè)置動(dòng)畫(huà)執(zhí)行的時(shí)間 ta.setFillAfter(true);//當(dāng)動(dòng)畫(huà)結(jié)束后 動(dòng)畫(huà)停留在結(jié)束位置,然后等啟動(dòng)主界面后將其銷(xiāo)毀 ll_splashActivity.startAnimation(ta); ta.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation arg0) { } @Override public void onAnimationRepeat(Animation arg0) { } @Override public void onAnimationEnd(Animation arg0) { Intent intent = new Intent(getApplicationContext(), MainActivity.class); startActivity(intent); finish(); } }); } }, 1000*4); } class MyCountDownTimer extends CountDownTimer { //millisInFuture:倒計(jì)時(shí)的總數(shù),單位毫秒 //例如 millisInFuture=1000;表示1秒 //countDownInterval:表示間隔多少毫秒,調(diào)用一次onTick方法() //例如: countDownInterval =1000;表示每1000毫秒調(diào)用一次onTick() public MyCountDownTimer(long millisInFuture, long countDownInterval) { super(millisInFuture, countDownInterval); } public void onFinish() { tv_countDown.setText("開(kāi)始跳轉(zhuǎn)……"); } public void onTick(long millisUntilFinished) { tv_countDown.setText("倒計(jì)時(shí)(" + millisUntilFinished / 1000 + ")"); } } }
五、MainActivity.java代碼
package com.zgs.SplashScreenByXml; import android.app.Activity; import android.os.Bundle; import com.zgs.CommonlySplashScreen.R; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //為了讓閃屏結(jié)束后更自然的過(guò)度到主界面,去除主界面的啟動(dòng)動(dòng)畫(huà),將下面函數(shù)的第一個(gè)參數(shù)設(shè)為0即可 overridePendingTransition(0, 0); } }
六、操作演示
以上所述是小編給大家介紹的Android中閃屏實(shí)現(xiàn)方法小結(jié)(普通閃屏、倒計(jì)時(shí)閃屏、倒計(jì)時(shí)+動(dòng)畫(huà)閃屏),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- Android實(shí)現(xiàn)閃屏效果
- Android 自定義閃屏頁(yè)廣告倒計(jì)時(shí)view效果
- Android中使用Handler及Countdowntimer實(shí)現(xiàn)包含倒計(jì)時(shí)的閃屏頁(yè)面
- Android應(yīng)用閃屏頁(yè)延遲跳轉(zhuǎn)的三種寫(xiě)法
- Android實(shí)現(xiàn)閃屏歡迎界面
- Android切換至SurfaceView時(shí)閃屏(黑屏閃一下)以及黑屏移動(dòng)問(wèn)題的解決方法
- Android實(shí)現(xiàn)閃屏及注冊(cè)和登錄界面之間的切換效果
- android實(shí)現(xiàn)Splash閃屏效果示例
- Android 實(shí)現(xiàn)閃屏頁(yè)和右上角的倒計(jì)時(shí)跳轉(zhuǎn)實(shí)例代碼
- Android實(shí)現(xiàn)應(yīng)用程序的閃屏效果
相關(guān)文章
Android studio報(bào)錯(cuò):The emulator process for AVD (xxx) was kill
這篇文章主要介紹了Android studio報(bào)錯(cuò):The emulator process for AVD (xxx) was killed,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12Android程序開(kāi)發(fā)之UIScrollerView里有兩個(gè)tableView
這篇文章主要介紹了UIScrollerView里有兩個(gè)tableView 的相關(guān)資料,需要的朋友可以參考下2016-04-04Android編程實(shí)現(xiàn)圓角邊框布局效果的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)圓角邊框布局效果的方法,結(jié)合實(shí)例形式分析了Android TableLayout布局的相關(guān)屬性操作與圓角邊框?qū)崿F(xiàn)技巧,需要的朋友可以參考下2017-06-06Kotlin之自定義 Live Templates詳解(模板代碼)
這篇文章主要介紹了Kotlin之自定義 Live Templates詳解(模板代碼),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-03-03Android?Flutter實(shí)現(xiàn)創(chuàng)意時(shí)鐘的示例代碼
時(shí)鐘這個(gè)東西很奇妙,總能當(dāng)做創(chuàng)意實(shí)現(xiàn)的入口。這篇文章主要介紹了如何通過(guò)Android?Flutter實(shí)現(xiàn)一個(gè)創(chuàng)意時(shí)鐘,感興趣的小伙伴可以了解一下2023-03-03android如何默認(rèn)打開(kāi)小區(qū)廣播具體實(shí)現(xiàn)
小區(qū)廣播的開(kāi)關(guān),1是打開(kāi),0是關(guān)閉;0x00就默認(rèn)關(guān)閉,改成0x01就是默認(rèn)打開(kāi),具體修改如下,感興趣的朋友可以參考下哈2013-06-06Android 開(kāi)發(fā)中l(wèi)ayout下的子文件夾
這篇文章主要介紹了android 開(kāi)發(fā)中l(wèi)ayout下的子文件夾,需要的朋友可以參考下2017-12-12Android?自定義開(kāi)源庫(kù)?EasyView實(shí)現(xiàn)詳解
這篇文章主要為大家介紹了Android自定義開(kāi)源庫(kù)EasyView實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-04-04