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,这里我们封装成一个控件,也方便大 ...
随机推荐
- 1310. ACM Diagnostics
http://acm.timus.ru/problem.aspx?space=1&num=1310 题目中说的 “the lexicographically increasing list” ...
- MSP430FR5739串口程序
今天急着用这个片子的串口,匆忙中调试串口也话费了一段时间,在网上下了一个程序,忽然就把所有问题搞清楚了,只是中断就看着头文件中寄存器写的,虽然通讯正常,不过不确定有没有写错.代码如下: #includ ...
- (转载)jQuery 1.6 源码学习(二)——core.js[2]之extend&ready方法
上次分析了extend方法的实现,而紧接着extend方法后面调用了jQuery.extend()方法(core.js 359行),今天来看看究竟core.js里为jQuery对象扩展了哪些静态方法. ...
- Leetcode_实现zigzag的转换_20161228
#include<iostream> //#include<valarray> #include<vector> #include<string> us ...
- VMware下利用ubuntu13.04建立嵌入式开发环境之五
tftp和nfs服务器配置 一.tftp服务器配置 1.安装软件包 1.1安装服务 apt-get install tftpd-hpa 1.2安装客户端 apt-get install tftp-hp ...
- 方法的重载overload
/*方法的重载overload * 重载:在同一个类里可以定义一个或者一个以上的方法 * 参数类型不一致 * 参数数量不一致 * */ public class Chongza ...
- Sqlite日期类型问题:该字符串未被识别为有效的 DateTime(String not recognized as a valid datetime)
使用SQLite抛出异常: 该字符串未被识别为有效的 DateTime 错误(String not recognized as a valid datetime) 解决方法: 也可以在连接字符串 修改 ...
- 关于GridView的第一个item图片加载不出来问题
首先感谢csdn里的id 大神了没 的博客 地址:http://blog.csdn.net/wenyiqingnianiii/article/details/39291667 原因在positi ...
- What does it mean to “delegate to a sister class” via virtual inheritance?
Consider the following example: class Base { public: ; ; }; class Der1 : public virtual Base { publi ...
- html+css知识点总结(田彦霞)
html部分 html头部声明 DOCTYPE是document type(文档类型)的简写,用来说明你用的XHTML或者HTML是什么版本.DOCTYPE声明必须放在每一个XHTML文档最顶部,在所 ...