Android---闪频页和倒计时
android闪频的实现非常简单,使用Handler对象的postDelayed()方法就可以实现。在这个方法里传递一个Runnable对象和一个延迟的时间。该方法实现了一个延迟执行的效果,延迟的时间由第2个参数指定,单位是毫秒。第一个参数是Runnable对象,里面包含了延迟后需要执行的操作。我在这里给他加了个简单的放大效果。下面贴上代码:
package com.msn.zn.splashdemo; import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView; public class SplashActivity extends Activity {
private ImageView iv_logo; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//取消标题
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//取消状态栏
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash);
iv_logo= (ImageView) findViewById(R.id.logo); //加载xml文件中的动画
Animation anim= AnimationUtils.loadAnimation(this,R.anim.splash);
iv_logo.startAnimation(anim); Handler handler=new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent=new Intent(SplashActivity.this,MainActivity.class);
startActivity(intent);
finish();
}
},3000);
}
}
布局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.msn.zn.splashdemo.SplashActivity">
<ImageView
android:id="@+id/logo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@mipmap/splasht2"/>
</RelativeLayout> 动画xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1500"
android:fillAfter="true">
<scale
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.1"
android:toYScale="1.1"/>
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.8"/>
<!--
duration="1500"设置动画的持续时间为1.5s
fillAfter="true"设置动画结束后保持当前的位置(即不返回动画开始前的位置)
这些也可以在代码中实现
animation.setDuration(1500);
animation.setFillAfter(true);
-->
</set>
倒计时效果图:
我是用了个android封装好了的一个倒计时类CountDownTimer,其实是将后台线程的创建和Handler队列封装成为了一个方便的类调用。下面附上代码:
package com.msn.zn.splashdemo;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.widget.TextView;
public class SplashTimeActivity extends Activity {
private TextView tv_time;
private MyCountDownTimer mc;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_time);
tv_time= (TextView) findViewById(R.id.tv_time);
mc=new MyCountDownTimer(5000,1000);
mc.start();//启动倒计时
handler.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent=new Intent(SplashTimeActivity.this,MainActivity.class);
startActivity(intent);
}
},5000);
}
private Handler handler=new Handler();
/**
* 定义一个倒计时的内部类
*/
class MyCountDownTimer extends CountDownTimer {
/**
*
* @param millisInFuture 从开始调用start()到倒计时完成并onfinish()方法被调用的毫秒数
* @param countDownInterval 接收onTick(long)回调的间隔时间
*/
public MyCountDownTimer(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onTick(long l) {
tv_time.setText("倒计时"+l/1000);
}
@Override
public void onFinish() {
tv_time.setText("正在跳转");
}
}
} 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"
android:background="@mipmap/splasht2"
tools:context="com.msn.zn.splashdemo.SplashTimeActivity">
<TextView
android:id="@+id/tv_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:textSize="20sp"
android:text="闪一下"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" /> </RelativeLayout>
Android---闪频页和倒计时的更多相关文章
- Android 引导页公共方法LeaderPager
SimpAndroidFarme是近期脑子突然发热想做的android快速开发的框架,目标是模块化 常用的控件,方便新手学习和使用.也欢迎老鸟来一起充实项目:项目地址 引导页是我们开发app很常用的功 ...
- Android—实现自定义相机倒计时拍照
这篇博客为大家介绍Android自定义相机,并且实现倒计时拍照功能 首先自定义拍照会用到SurfaceView控件显示照片的预览区域,以下是布局文件: 两个TextView是用来显示提示信息和倒计时的 ...
- Android自定义View之倒计时Countdown实现
先看一下效果: 在点击OK键之后,开始倒计时. 实现步骤 1.新建Android工程"CountdownView" 2.自定义Drawable 自定义View并没有直接的用户交互, ...
- Android引导页设计
大家在安装好一个应用后,第一次打开时往往会出现一个使用引导页,形式一般为三.四张图片,随着我们的滑动进行切换,在最后一页会有一个进入应用的按钮,我们通过点击这个按钮可以进入应用,其实这其中没有太多的复 ...
- [转]Android实现计时与倒计时(限时抢购)的几种方法
在购物网站的促销活动中一般都有倒计时限制购物时间或者折扣的时间,这些都是如何实现的呢? 在一个安卓客户端项目中恰好遇到了类似的问题,一开始使用的是Timer与 TimerTask, 虽然此方法通用,但 ...
- Android基础之CountDownTimer 倒计时类
app常用的60s倒计时计时功能: private static final int TIME_LIMIT = 60; private void initView() { // 相关控件 mResen ...
- android引导页的实现 及跳转到主页面
第一个activity package com.qualitypicture.activity; import java.util.ArrayList; import java.util.List; ...
- Xamarin.Android 引导页
http://blog.csdn.net/qq1326702940/article/details/78665588 https://www.cnblogs.com/catcher1994/p/555 ...
- android 特卖列表倒计时卡顿问题
在Android的开发中,我们经常遇见倒计时的操作,通常使用Timer和Handler共同操作来完成.当然也可以使用Android系统控件CountDownTimer,这里我们封装成一个控件,也方便大 ...
随机推荐
- Android中ListView的用法
使用方法1 显示简单的文本 在layout文件中像加入普通控件一样在layout文件中引入ListView <ListView android:id="@+id/list_view&q ...
- [翻译]PYTHON中如何使用*ARGS和**KWARGS
[翻译]Python中如何使用*args和**kwargs 函数定义 函数调用 不知道有没有人翻译了,看到了,很短,顺手一翻 原文地址 入口 或者可以叫做,在Python中如何使用可变长参数列表 函数 ...
- UDPClient的用法
UDP_Server: UdpClient receivingUdpClient = ); IPEndPoint RemoteIpEndPoint = ); try { byte[] sdata = ...
- CBitmap、HBITMAP、BITMAP相互转换
一:理解 BITMAP是C++中定义的位图结构体 HBITMAP是Windows中使用的位图句柄 CBitmap是MFC封装的位图类 二:相互转换 1.HBITMAP->CBitmap 方法一: ...
- 使用jQuery,实现完美的表单异步提交
jQuery异步提交表单 <form id="form1" method="post"> <table border="1" ...
- 如果Python中有很多换行,可以选择使用"""..."""表示多行内容
举例:>>> print("""... ... ... ... ... ... ... ... ''')... fdfd""&quo ...
- PHP JS JQ 异步上传并立即显示图片
提交页面: <! DOCTYPE html> < html> < head> < meta charset ="GB2312" > ...
- Learning in Two-Player Matrix Games
3.2 Nash Equilibria in Two-Player Matrix Games For a two-player matrix game, we can set up a matrix ...
- OGG for DB2 i 12.2发布
2016-04-15 Oracle发布了GoldenGate for DB2 i 12.2.0.1.2,软件可以从OTN 或 eDelivery下载.这是第一个针对DB2 for i的12.2版本.此 ...
- TeamWork-天气美食
一. 团队情况 Hello,欢迎来到我们"Code Man"队的第一次团队作业页面,"代码侠"很明显我们是一个编程队伍,由大三在读的6位同班同学组成 ...