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

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

概述一、项目目录结构二、activity_main.xml代码<RelativeLayoutxmlns:android=\"http://schemas.android.com/apk/res/android\"

一、项目目录结构

二、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);     /********************************************************************************      *      * 普通闪屏实现方式      *      * ******************************************************************************/     /*new Handler().postDelayed(new Runnable() {       @OverrIDe       public voID run() {         Intent intent = new Intent(getApplicationContext(),MainActivity.class);         startActivity(intent);         finish();       }     },1000*4);*/     /********************************************************************************      *      * 倒计时闪屏实现方式      *      * ******************************************************************************/     /*MyCountDownTimer mc = new MyCountDownTimer(4000,1000);     mc.start();     new Handler().postDelayed(new Runnable() {       @OverrIDe       public voID run() {         Intent intent = new Intent(getApplicationContext(),1000*4);*/     /********************************************************************************      *      * 倒计时+动画闪屏实现方式      *      * ******************************************************************************/     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,Animation.relative_TO_PARENT,-1,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中闪屏实现方法小结(普通闪屏、倒计时闪屏、倒计时+动画闪屏)所遇到的程序开发问题。

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

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

原文地址: http://www.outofmemory.cn/web/1147311.html

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

发表评论

登录后才能评论

评论列表(0条)

保存