Android實(shí)現(xiàn)閃屏歡迎界面
閃屏:在打開App時,展示,持續(xù)數(shù)秒后,自動關(guān)閉,進(jìn)入另外的一個界面,SplashActivity跳轉(zhuǎn)到MainActivity
Android中有三種實(shí)現(xiàn)方法
xml代碼:
<?xml version="1.0" encoding="utf-8"?> <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" tools:context="com.example.administrator.test.SplashActivity"> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/splash_iv" android:scaleType="fitXY" android:src="@mipmap/splash"/> </RelativeLayout>
(1)利用Handler對象的postDelayed方法可以實(shí)現(xiàn),傳遞一個Runnable對象和一個需要延時的時間即可
new Handler().postDelayed(new Runnable() { @Override public void run() { Intent intent=new Intent(SplashActivity.this,MainActivity.class); startActivity(intent); SplashActivity.this.finish(); } },3000);
(2)使用動畫持續(xù)時間,動畫結(jié)束后進(jìn)行跳轉(zhuǎn)
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); iv =(ImageView)findViewById(R.id.splash_iv); iv.setImageResource(R.mipmap.splash); //設(shè)置透明度動畫從無到有 AlphaAnimation alphaAnimation=new AlphaAnimation(0.0f,1.0f); //設(shè)置動畫持續(xù)時間 alphaAnimation.setDuration(3000); //開始顯示動畫 iv.startAnimation(alphaAnimation); //給動畫設(shè)置監(jiān)聽,在動畫結(jié)束的時候進(jìn)行跳轉(zhuǎn) alphaAnimation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { //動畫開始時執(zhí)行 Log.e("TAG", "onAnimationStart: " ); } @Override public void onAnimationEnd(Animation animation) { //動畫結(jié)束時執(zhí)行 Log.e("TAG", "onAnimationEnd: " ); Intent intent=new Intent(SplashActivity.this,MainActivity.class); startActivity(intent); finish(); } @Override public void onAnimationRepeat(Animation animation) { //動畫重復(fù)播放時執(zhí)行 Log.e("TAG", "onAnimationRepeat: " ); } }); }
(3)利用Timer定時器實(shí)現(xiàn),
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); iv =(ImageView)findViewById(R.id.splash_iv); iv.setImageResource(R.mipmap.splash); Timer timer=new Timer(); timer.schedule(new TimerTask() { @Override public void run() { Intent intent=new Intent(SplashActivity.this,MainActivity.class); startActivity(intent); finish(); } },3000); }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
神經(jīng)網(wǎng)絡(luò)API、Kotlin支持,那些你必須知道的Android 8.1預(yù)覽版和Android Studio 3.0新特
這篇文章主要介紹了神經(jīng)網(wǎng)絡(luò)API、Kotlin支持,那些你必須了解的Android 8.1預(yù)覽版和Android Studio 3.0新特性,需要的朋友可以參考下2017-10-10Android listview定位到上次顯示的位置的實(shí)現(xiàn)方法
這篇文章主要介紹了Android listview定位到上次顯示的位置的實(shí)現(xiàn)方法的相關(guān)資料,希望通過本文能幫助到大家,需要的朋友可以參考下2017-08-08Android設(shè)備獲取掃碼槍掃描的內(nèi)容與可能遇到的問題解決
這篇文章主要給大家介紹了關(guān)于Android設(shè)備獲取掃碼槍掃描內(nèi)容的方法,以及在開發(fā)中可能會遇到的問題的解決方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧。2017-11-11Android ViewPager實(shí)現(xiàn)圖片輪播效果
這篇文章主要為大家詳細(xì)介紹了Android ViewPager實(shí)現(xiàn)圖片輪播效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09Android 之BottomsheetDialogFragment仿抖音評論底部彈出對話框效果(實(shí)例代碼)
這篇文章主要介紹了Android 中之BottomsheetDialogFragment仿抖音評論底部彈出對話框效果,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-04-04android實(shí)現(xiàn)簡單進(jìn)度條ProgressBar效果
這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)簡單進(jìn)度條ProgressBar效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-07-07Android 系統(tǒng)實(shí)現(xiàn)多種開機(jī)動畫和logo切換功能
這篇文章主要介紹了android 系統(tǒng)實(shí)現(xiàn)多種開機(jī)動畫和logo切換功能,非常不錯,具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-12-12