国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android實現閃屏歡迎界面

2019-10-23 19:49:12
字體:
來源:轉載
供稿:網友

閃屏:在打開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);  }

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 巢湖市| 镇平县| 闽侯县| 寿光市| 布拖县| 通河县| 页游| 都兰县| 大悟县| 什邡市| 白河县| 昭苏县| 车险| 仁布县| 益阳市| 南昌市| 东城区| 青神县| 烟台市| 台南市| 吴江市| 南丹县| 页游| 木里| 达拉特旗| 稻城县| 故城县| 新干县| 怀仁县| 尚志市| 青岛市| 辽源市| 鞍山市| 嘉义县| 孝昌县| 西城区| 香港| 阜阳市| 韶关市| 安阳县| 赞皇县|