广告
返回顶部
首页 > 资讯 > 移动开发 >Android中闪屏实现方法小结(普通闪屏、倒计时闪屏、倒计时+动画闪屏)
  • 819
分享到

Android中闪屏实现方法小结(普通闪屏、倒计时闪屏、倒计时+动画闪屏)

闪屏倒计时小结方法动画Android 2022-06-06 04:06:43 819人浏览 独家记忆
摘要

一、项目目录结构 二、activity_main.xml代码 <RelativeLayout xmlns:Android="Http://schemas.androi

一、项目目录结构

二、activity_main.xml代码


<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" 
  android:paddingBottom="@dimen/activity_vertical_margin" 
  android:paddingLeft="@dimen/activity_horizontal_margin" 
  android:paddingRight="@dimen/activity_horizontal_margin" 
  android:paddingTop="@dimen/activity_vertical_margin" 
  tools:context="com.zgs.SplashScreenByXml.MainActivity" > 
  <TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="主页面" /> 
</RelativeLayout> 

三、activity_splashscreen.xml代码


<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent" 
  android:background="@drawable/splash" 
  android:orientation="vertical"  
  android:id="@+id/ll_splashActivity"> 
  <TextView 
    android:id="@+id/tv_countDown" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="end" 
    android:layout_marginEnd="20dp" 
    android:layout_marginTop="20dp" 
    android:textColor="@android:color/white" 
    android:textSize="20sp" /> 
</LinearLayout> 

四、SplashScreenActiviy.java代码


package com.zgs.SplashScreenByXml; 
import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.os.CountDownTimer; 
import android.os.Handler; 
import android.view.View; 
import android.view.Window; 
import android.view.WindowManager; 
import android.view.animation.Animation; 
import android.view.animation.Animation.AnimationListener; 
import android.view.animation.TranslateAnimation; 
import android.widget.LinearLayout; 
import android.widget.TextView; 
import com.zgs.CommonlySplashScreen.R; 
public class SplashScreenActiviy extends Activity { 
  private TextView tv_countDown; 
  private LinearLayout ll_splashActivity; 
  @Override 
  protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    // 通过下面两行代码也可实现全屏无标题栏显示activity 
    // getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    // this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    setContentView(R.layout.activity_splashscreen); 
    tv_countDown = (TextView) findViewById(R.id.tv_countDown); 
    ll_splashActivity = (LinearLayout) findViewById(R.id.ll_splashActivity); 
     
     
     
     
     
    MyCountDownTimer mc = new MyCountDownTimer(4000, 1000);  
    mc.start(); 
    new Handler().postDelayed(new Runnable() { 
      @Override 
      public void run() { 
        //左移动画 
        TranslateAnimation ta = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, -1, Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0);  
        ta.setDuration(2000); //设置动画执行的时间 
        ta.setFillAfter(true);//当动画结束后 动画停留在结束位置,然后等启动主界面后将其销毁 
        ll_splashActivity.startAnimation(ta); 
        ta.setAnimationListener(new AnimationListener() { 
          @Override 
          public void onAnimationStart(Animation arg0) { 
          } 
          @Override 
          public void onAnimationRepeat(Animation arg0) { 
          } 
          @Override 
          public void onAnimationEnd(Animation arg0) { 
            Intent intent = new Intent(getApplicationContext(), MainActivity.class); 
            startActivity(intent); 
            finish(); 
          } 
        }); 
      } 
    }, 1000*4); 
  } 
  class MyCountDownTimer extends CountDownTimer {  
    //millisInFuture:倒计时的总数,单位毫秒 
    //例如 millisInFuture=1000;表示1秒 
    //countDownInterval:表示间隔多少毫秒,调用一次onTick方法() 
    //例如: countDownInterval =1000;表示每1000毫秒调用一次onTick() 
    public MyCountDownTimer(long millisInFuture, long countDownInterval) {  
      super(millisInFuture, countDownInterval);  
    }  
    public void onFinish() {  
      tv_countDown.setText("开始跳转……"); 
    }  
    public void onTick(long millisUntilFinished) {  
      tv_countDown.setText("倒计时(" + millisUntilFinished / 1000 + ")"); 
    }  
  } 
} 

五、MainActivity.java代码


package com.zgs.SplashScreenByXml; 
import android.app.Activity; 
import android.os.Bundle; 
import com.zgs.CommonlySplashScreen.R; 
public class MainActivity extends Activity { 
  @Override 
  protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    //为了让闪屏结束后更自然的过度到主界面,去除主界面的启动动画,将下面函数的第一个参数设为0即可 
    overridePendingTransition(0, 0); 
  } 
} 

六、操作演示

以上所述是小编给大家介绍的Android中闪屏实现方法小结(普通闪屏、倒计时闪屏、倒计时+动画闪屏),希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程网网站的支持!

您可能感兴趣的文章:Android实现闪屏效果Android 自定义闪屏页广告倒计时view效果Android中使用Handler及Countdowntimer实现包含倒计时的闪屏页面Android应用闪屏页延迟跳转的三种写法Android实现闪屏欢迎界面Android切换至SurfaceView时闪屏(黑屏闪一下)以及黑屏移动问题的解决方法Android实现闪屏及注册和登录界面之间的切换效果android实现Splash闪屏效果示例Android 实现闪屏页和右上角的倒计时跳转实例代码Android实现应用程序的闪屏效果


--结束END--

本文标题: Android中闪屏实现方法小结(普通闪屏、倒计时闪屏、倒计时+动画闪屏)

本文链接: https://www.lsjlt.com/news/22705.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作