Android实现闪屏欢迎界面

Android实现闪屏欢迎界面,第1张

概述闪屏:在打开App时,展示,持续数秒后,自动关闭,进入另外的一个界面,SplashActivity跳转到MainActivity

闪屏:在打开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实现闪屏欢迎界面所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1147073.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存