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

首頁(yè) > 系統(tǒng) > Android > 正文

Android實(shí)現(xiàn)閃屏歡迎界面

2019-12-12 03:49:48
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

閃屏:在打開(kāi)App時(shí),展示,持續(xù)數(shù)秒后,自動(dòng)關(guān)閉,進(jìn)入另外的一個(gè)界面,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對(duì)象的postDelayed方法可以實(shí)現(xiàn),傳遞一個(gè)Runnable對(duì)象和一個(gè)需要延時(shí)的時(shí)間即可

 new Handler().postDelayed(new Runnable() {      @Override      public void run() {        Intent intent=new Intent(SplashActivity.this,MainActivity.class);        startActivity(intent);        SplashActivity.this.finish();      }    },3000);

(2)使用動(dòng)畫(huà)持續(xù)時(shí)間,動(dòng)畫(huà)結(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è)置透明度動(dòng)畫(huà)從無(wú)到有    AlphaAnimation alphaAnimation=new AlphaAnimation(0.0f,1.0f);    //設(shè)置動(dòng)畫(huà)持續(xù)時(shí)間    alphaAnimation.setDuration(3000);    //開(kāi)始顯示動(dòng)畫(huà)    iv.startAnimation(alphaAnimation);    //給動(dòng)畫(huà)設(shè)置監(jiān)聽(tīng),在動(dòng)畫(huà)結(jié)束的時(shí)候進(jìn)行跳轉(zhuǎn)    alphaAnimation.setAnimationListener(new Animation.AnimationListener() {      @Override      public void onAnimationStart(Animation animation) {        //動(dòng)畫(huà)開(kāi)始時(shí)執(zhí)行        Log.e("TAG", "onAnimationStart: " );      }      @Override      public void onAnimationEnd(Animation animation) {        //動(dòng)畫(huà)結(jié)束時(shí)執(zhí)行        Log.e("TAG", "onAnimationEnd: " );        Intent intent=new Intent(SplashActivity.this,MainActivity.class);        startActivity(intent);        finish();      }      @Override      public void onAnimationRepeat(Animation animation) {        //動(dòng)畫(huà)重復(fù)播放時(shí)執(zhí)行        Log.e("TAG", "onAnimationRepeat: " );      }    });  }

(3)利用Timer定時(shí)器實(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);  }

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 灵丘县| 屯留县| 漳平市| 土默特右旗| 闽清县| 万州区| 鹿泉市| 铜陵市| 外汇| 永吉县| 宜宾市| 中山市| 麻栗坡县| 定日县| 临朐县| 安泽县| 阜平县| 富川| 封开县| 临邑县| 甘洛县| 博湖县| 镶黄旗| 玉山县| 中牟县| 宜城市| 隆子县| 琼结县| 桓台县| 长岭县| 嫩江县| 友谊县| 桑日县| 旌德县| 密山市| 安庆市| 宁武县| 扬中市| 吕梁市| 克拉玛依市| 江西省|