效果图:


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

MainActivity

package com.bwie.com.myapplication;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() {@Override
        public void handleMessage(Message msg) {super.handleMessage(msg);setTime();sendEmptyMessageDelayed(0, 1000);}};@Override
    protected 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"><LinearLayout
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:gravity="center_vertical"><TextView

            android:id="@+id/tv_miaosha"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:text="京东秒杀"
            android:textColor="#f00" /><TextView
            android:id="@+id/tv_miaosha_time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:text="10点场" /><LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"><TextView
                android: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" /><TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="3dp"

                android:text=":" /><TextView
                android: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" /><TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="3dp"

                android:text=":" /><TextView
                android: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京东秒杀倒计时,js实现京东秒杀倒计时功能

    本文实例为大家分享了js实现京东秒杀倒计时功能的具体代码,供大家参考,具体内容如下 首先给大家看看效果图,因为是做的移动端的,所以放大给大家看看局部就行: 关于实现京东秒杀,之前用过其他的方法,今天给 ...

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

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

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

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

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

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

  5. Android——仿京东秒杀

    效果图: 京东秒杀是两个小时一个场次,判断本机的时间进行场次定时,然后在这两个小时里面进行倒计时. MainActivity import android.os.Handler; import and ...

  6. 首页广告(轮播图+京东秒杀+最底部的为你推荐)

    首先在Api中添加URL接口 String AD_URL="https://www.zhaoapi.cn/ad/getAd"; bean包中解析接口数据 import java.u ...

  7. 小猿圈Python之实现京东秒杀功能代码

    现在电商产业的多种多样,从最早的阿里巴巴.淘宝到现在的京东等等数不胜数,你还记得的京东的秒杀功能吗?小猿圈python讲师今天就为你实现京东秒杀功能代码. #Python3.5 #coding:utf ...

  8. 如何使用python编程抢京东优惠券 知乎_小猿圈Python之实现京东秒杀功能技巧

    现在电商盛起,活动页面一个接着一个,一般都是抢购.秒杀,看着很刺激吧,这篇文章小猿圈加加就揭开这些秒杀功能的面纱,带你们看看实际的面貌,让我们学习一下代码吧. #Python3.5 #coding:u ...

  9. 如何使用python编程抢京东优惠券 知乎_小猿圈Python之实现京东秒杀功能代码

    现在电商产业的多种多样,从最早的阿里巴巴.淘宝到现在的京东等等数不胜数,你还记得的京东的秒杀功能吗?小猿圈python讲师今天就为你实现京东秒杀功能代码. #Python3.5 #coding:utf ...

  10. python京东预约抢购_Python实现京东秒杀功能代码

    本文实例为大家分享了Python实现京东秒杀功能的具体代码,供大家参考,具体内容如下 #Python 3.5 #coding:utf-8 #import scrapy from selenium im ...

最新文章

  1. Android线程模型和AsyncTask
  2. Django学习笔记之——Forms
  3. 三维重建PCL:点云单侧面正射投影
  4. SAP的软件是如何深刻影响着世界的?
  5. OC Autorelease
  6. python蓝牙编程_蓝牙编程经典程序!
  7. MyBatis-Plus_断言
  8. 1.10 编程基础之简单排序 06 整数奇偶排序 python
  9. Linux基础学习二:计算机组成以及Linux简单配置
  10. mac 2k显示器字体发虚_精准色彩体验-优派VP2785-2K
  11. php获取远程图片模拟post,file上传到指定服务器
  12. OpenCV中的内存泄露问题(cvLoadImage,cvCloneImage)【转】
  13. vs2015 2017 2019社区版免登录延长许可证
  14. 安卓 基于百度LBS的定位
  15. 6-3 jmu-python-函数-找钱 (10分)
  16. ARM Cortex 详解
  17. 网页特效--图片淡入淡出效果
  18. 对接快递100快递管家API之如何实现自动打单
  19. readxmls r语言_R语言批量爬取NCBI基因注释数据
  20. Access-Control-Allow-Origin: Dealing with CORS Errors in Angular

热门文章

  1. 称之幸运的ブドゥー人偶
  2. zzq的离散数学教室1
  3. 使用CMake 结合VisualStudio工程使用LINK_DIRECTORIES指令发生LNK1104 “无法打开文件xxx.lib”问题踩坑
  4. 《仿人机器人原理与实战》一3.3 热平衡模拟器
  5. .Net 日志系统-常用日志框架
  6. ue4圆形血条_UE4_fUI_血条 耐力条
  7. IEEE754数据转换详解
  8. 如何选择安全可靠质量好的移动电源
  9. 什么移动电源质量好,质量好的移动电源推荐
  10. Fiddler everywhere 4.0.1抓包工具 修改教程