效果图:

京东秒杀是两个小时一个场次,判断本机的时间进行场次定时,然后在这两个小时里面进行倒计时。

MainActivity

import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;public class MainActivity extends AppCompatActivity {private TextView miaosha_time;private TextView miaosha_shi;private TextView miaosha_minter;private TextView miaosha_second;private Handler handler = new Handler() {@Overridepublic void handleMessage(Message msg) {super.handleMessage(msg);setTime();sendEmptyMessageDelayed(0, 1000);}};@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);initView();handler.sendEmptyMessage(0);}public void initView(){miaosha_time = (TextView) findViewById(R.id.tv_miaosha_time);miaosha_shi = (TextView) findViewById(R.id.tv_miaosha_shi);miaosha_minter = (TextView) findViewById(R.id.tv_miaosha_minter);miaosha_second = (TextView) findViewById(R.id.tv_miaosha_second);}//秒杀倒计时public void setTime() {SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");Date curDate = new Date(System.currentTimeMillis());String format = df.format(curDate);StringBuffer buffer = new StringBuffer();String substring = format.substring(0, 11);buffer.append(substring);Log.d("ccc", substring);Calendar calendar = Calendar.getInstance();int hour = calendar.get(Calendar.HOUR_OF_DAY);if (hour % 2 == 0) {miaosha_time.setText(hour + "点场");buffer.append((hour + 2));buffer.append(":00:00");} else {miaosha_time.setText((hour - 1) + "点场");buffer.append((hour + 1));buffer.append(":00:00");}String totime = buffer.toString();try {java.util.Date date = df.parse(totime);java.util.Date date1 = df.parse(format);long defferenttime = date.getTime() - date1.getTime();long days = defferenttime / (1000 * 60 * 60 * 24);long hours = (defferenttime - days * (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);long minute = (defferenttime - days * (1000 * 60 * 60 * 24) - hours * (1000 * 60 * 60)) / (1000 * 60);long seconds = defferenttime % 60000;long second = Math.round((float) seconds / 1000);miaosha_shi.setText("0" + hours + "");if (minute >= 10) {miaosha_minter.setText(minute + "");} else {miaosha_minter.setText("0" + minute + "");}if (second >= 10) {miaosha_second.setText(second + "");} else {miaosha_second.setText("0" + second + "");}} catch (ParseException e) {e.printStackTrace();}}
}

布局文件:

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context="com.bwie.com.myapplication.MainActivity"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="40dp"android:gravity="center_vertical"><TextViewandroid:id="@+id/tv_miaosha"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:text="京东秒杀"android:textColor="#f00" /><TextViewandroid:id="@+id/tv_miaosha_time"android:layout_width="wrap_content"android:layout_height="wrap_content"android:padding="5dp"android:text="10点场" /><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"><TextViewandroid:id="@+id/tv_miaosha_shi"android:layout_width="15dp"android:layout_height="15dp"android:background="@drawable/shape_miaosha_time"android:gravity="center"android:text="1"android:textColor="#fff"android:textSize="10sp" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:padding="3dp"android:text=":" /><TextViewandroid:id="@+id/tv_miaosha_minter"android:layout_width="15dp"android:layout_height="15dp"android:background="@drawable/shape_miaosha_time"android:gravity="center"android:text="1"android:textColor="#fff"android:textSize="10sp" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:padding="3dp"android:text=":" /><TextViewandroid:id="@+id/tv_miaosha_second"android:layout_width="15dp"android:layout_height="15dp"android:background="@drawable/shape_miaosha_time"android:gravity="center"android:text="1"android:textColor="#fff"android:textSize="10sp" /></LinearLayout></LinearLayout>
</RelativeLayout>

shape_miaosha_time.xml(对倒计时小黑框圆角的实现)

<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle"xmlns:android="http://schemas.android.com/apk/res/android"><solid android:color="#000"></solid><corners android:radius="3dp"></corners></shape>

一个和京东一模一样的秒杀倒计时就实现了,是不是很简单。

Android——仿京东秒杀相关推荐

  1. android高仿京东秒杀,Android仿京东首页秒杀倒计时

    本文实例为大家分享了Android仿京东首页秒杀倒计时的具体代码,供大家参考,具体内容如下 xml配置 android:layout_width="wrap_content" an ...

  2. android高仿京东秒杀,Android通过实现GridView的横向滚动实现仿京东秒杀效果

    实现GridView的横向滚动 效果如下图: 具体实现的代码 •1. 主界面布局代码:activity_main.xml android:layout_width="fill_parent& ...

  3. android高仿京东秒杀,Android实现京东秒杀界面

    本文实例为大家分享了Android实现京东秒杀界面展示的具体代码,供大家参考,具体内容如下 效果图: 京东秒杀是两个小时一个场次,判断本机的时间进行场次定时,然后在这两个小时里面进行倒计时. Main ...

  4. [Android]仿京东手机端类别页

    [Android]仿京东手机端类别页 京东手机端的类别标签页, 是一个左侧滑动可选择类别, 右侧一个类别明细的列表联动页面. 当用户选择左侧选项, 可在右侧显示更多选项来选择. 实现方式也不少. 最常 ...

  5. Android仿京东、天猫商品详情页

    前言 前面在介绍控件TabLayout控件和CoordinatorLayout使用的时候说了下实现京东.天猫详情页面的效果,今天要说的是优化版,是我们线上实现的效果,首先看一下效果: 项目结构分析 首 ...

  6. Android仿京东收货地址

    Android仿京东三级联动收货地址 1.在本地新建assets目录,存放三级联动json数据,取本地json数据作为数据源 String data = com.miles.zcstc.fingerd ...

  7. android自定义视频列表,Android仿京东天猫列表页播视频看这一篇就足够了

    阅读本文解决什么问题? 解决android 滑动列表页自动播视频中的一些技术难点.助力更好的实现类似需求.不涉及到播放器的具体编解码技术,因为各家用的播放器可能都不一样(其实是我不会~) 何时播视频最 ...

  8. android京东商城一级分类到二级分类的滑动效果,Android仿京东分类模块左侧分类条目效果...

    本文实例为大家分享了Android仿京东左侧分类条目效果的具体代码,供大家参考,具体内容如下 import android.app.Activity; import android.os.Bundle ...

  9. html js秒杀倒计时,JavaScript仿京东秒杀倒计时代码实例

    本篇文章小编给大家分享一下JavaScript仿京东秒杀倒计时代码实例,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看. 仿京东秒杀倒计时 html代码 秒杀倒计时 : : c ...

最新文章

  1. CHANGE_DOCUMENT
  2. python 培训-Python培训周末班|python是什么?能干什么?
  3. 【初码干货】关于.NET玩爬虫这些事
  4. hive命令出现问题Failed with exception Java.io.IOException:java.lang.IllegalArgumentException: java.NET.URI
  5. 8.用MyEclipse进行JSP开发
  6. 安卓牛客专项练习2020.12.10
  7. PostgreSQL 增量备份详解以及相关示例
  8. C 库函数 - pow()
  9. 华为机试HJ62:查找输入整数二进制中1的个数
  10. hash算法_HASH算法简介
  11. CSS的继承层叠和特殊性 样式的继承和优先级属性
  12. 5.网络层(3)---路由选择协议
  13. SpringBoot使用菜鸟物流云打印电子面单
  14. 编程语言习题集(1)
  15. 算法竞赛入门经典 排列
  16. 电力电子,电机控制系统的建模与仿真
  17. Vimac 0.3.14最新版 (一款让你用键盘代替鼠标软件)
  18. iOS UIViewController跳转
  19. Python web框架之tornado(龙卷风)
  20. 金融系列-会计基础知识

热门文章

  1. 人生不惑,钻研技术——ZFS和LVM
  2. 论文笔记-Domain Adaptation for Semantic Segmentation with Maximum Squares Loss
  3. QQSpider qq空间爬虫
  4. 英语教师计算机研修总结报告,英语教师研修总结范文(通用5篇)
  5. Win8安装程序出现2502、2503错误解决方法
  6. Spark:利用tac+cellid基站定位
  7. Froala富文本编辑器
  8. 利用微信小程序API获取所在位置周围的WIFI信息
  9. 用java定义中国象棋的棋子_java大神 求帮忙 我坐的中国象棋怎样移动棋子
  10. java输入长和宽输出面积_JAVA根据用户输入的长和宽,编程求长方形的面积和周长....