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,这里我们封装成一个控件,也方便大 ...
随机推荐
- 【 2013 Multi-University Training Contest 8 】
HDU 4678 Mine 对于每个空白区域,求SG值. 最后异或起来等于0,先手必败. #pragma comment(linker,"/STACK:102400000,102400000 ...
- recovery编译问题汇总
1.修改支持USB大容量存储 (1).首先需要查看手机lun位置 手机链接电脑,打开cmd命令行,依次输入以下命令: adb shell find /sys -name "lun" ...
- Bestcoder Round 47 && 48
1.Senior's Array(hdu 5280) 题目大意:给出大小为N的数组和P,求将数组中的某个元素替换为P后的最大连续子段和.N<=1000 题解: 1.送分题,比赛的时候只想到枚举替 ...
- Python Day04
一.迭代器与生成器: 迭代器(iterator): 迭代器是访问集合元素的一种方式.迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问完结束.迭代器只能往前不会后退,迭代器的一大优点是不要求事 ...
- CSS3背景
1.背景的五种基本属性 background-color(背景颜色) background-image(背景图片) background-repeat(背景图片展示方式) background-a ...
- Java在JFinal中出现Can not create instance of class: com.keesail.web.config.WebConfig异常处理方式
编译的时候一直出现如下问题: 后面 查了许多资料 说是build项目的时候web.xml没有输出到class目录.后面试了很多方式不行.后面自己摸索出如下方式解决问题: 改成默认输出目录.
- log4j日志-liu
log4j日志级别: http://michales003.iteye.com/blog/1160605 log4j日志配置详解: http://www.cnblogs.com/ITtangtang/ ...
- odi 12.2.1.1新特性
ODI 12.2.1.1现在已经发布,也可以OTN上下载,主要变化: Hyperion Essbase and Hyperion Planning 知识模块 Hyperion Essbase and ...
- 安全协议系列(三)----CCMP与WPA-PSK
本节讨论 CCM 在 WiFi 中的实际应用 -- CCMP 协议 根据 RFC 3610,完成 CCMP 报文的加解密,需要提供:分组密钥(K).随机数(Nonce).附加认证数据(AAD),这三个 ...
- Xcode清除缓存、清理多余证书
Xcode清除缓存.清理多余证书 1.删除Xcode中多余的证书provisioning profile 手动删除: Xcode6 provisioning profile path: ~/Libra ...