編輯:關於Android編程
閃屏:在打開App時,展示,持續數秒後,自動關閉,進入另外的一個界面,SplashActivity跳轉到MainActivity
Android中有三種實現方法
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方法可以實現,傳遞一個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)使用動畫持續時間,動畫結束後進行跳轉
@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);
//設置透明度動畫從無到有
AlphaAnimation alphaAnimation=new AlphaAnimation(0.0f,1.0f);
//設置動畫持續時間
alphaAnimation.setDuration(3000);
//開始顯示動畫
iv.startAnimation(alphaAnimation);
//給動畫設置監聽,在動畫結束的時候進行跳轉
alphaAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
//動畫開始時執行
Log.e("TAG", "onAnimationStart: " );
}
@Override
public void onAnimationEnd(Animation animation) {
//動畫結束時執行
Log.e("TAG", "onAnimationEnd: " );
Intent intent=new Intent(SplashActivity.this,MainActivity.class);
startActivity(intent);
finish();
}
@Override
public void onAnimationRepeat(Animation animation) {
//動畫重復播放時執行
Log.e("TAG", "onAnimationRepeat: " );
}
});
}
(3)利用Timer定時器實現,
@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);
}
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持本站。
仿Android印象筆記底部導航欄
最近用上了印象筆記,覺得android 版的底部導航欄挺不錯的,好多應用裡面都有用到,想著自己動手實現一下,不多說,先上圖: 要完成這樣的效果。需要自定義ViewGrou
Android設計模式之工廠模式 Factory
一.概述平時做項目跟使用第三方類庫的時候經常會用到工廠模式.什麼是工廠模式,簡單來說就是他的字面意思.給外部批量提供相同或者不同的產品,而外部不需要關心工廠是如何創建一個
Volley源碼分析
流程圖盜張網上的流程圖源碼分析構建RequestQueueVolley 的調用比較簡單,通過 newRequestQueue(…) 函數新建並啟動一個請求隊
Android異步加載全解析之使用多線程
異步加載之使用多線程初次嘗試異步、異步,其實說白了就是多任務處理,也就是多線程執行,多線程那就會有各種問題,我們一步步來看,首先,我們創建一個class—&m