当前位置: 移动技术网 > IT编程>移动开发>Android > Android实现闪屏欢迎界面

Android实现闪屏欢迎界面

2019年07月24日  | 移动技术网IT编程  | 我要评论

本钢女老板,下载变形金刚3,麦当网

闪屏:在打开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);
  }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网