欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android仿京東首頁秒殺倒計時

 更新時間:2019年01月21日 16:58:32   作者:拉莫帥  
這篇文章主要為大家詳細介紹了Android仿京東首頁秒殺倒計時,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Android仿京東首頁秒殺倒計時的具體代碼,供大家參考,具體內(nèi)容如下

xml配置

<LinearLayout
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:background="#FFFFFF"
  android:orientation="vertical">
  <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="8dp"
   android:text="京東秒殺"
   android:textColor="#f00"
   android:textSize="20sp" />
  <TextView
   android:id="@+id/tv_miaosha_time"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:padding="5dp"
   android:text="12點場"
   android:textSize="20sp" />
  <LinearLayout
   android:layout_width="wrap_content"
   android:layout_height="wrap_content">
   <TextView
   android:id="@+id/tv_miaosha_shi"
   android:layout_width="25dp"
   android:layout_height="25dp"
   android:background="@drawable/shape_miaosha_time"
   android:gravity="center"
   android:text="1"
   android:textColor="#fff"
   android:textSize="15sp" />
   <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="25dp"
   android:layout_height="25dp"
   android:background="@drawable/shape_miaosha_time"
   android:gravity="center"
   android:text="1"
   android:textColor="#fff"
   android:textSize="15sp" />
   <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="25dp"
   android:layout_height="25dp"
   android:background="@drawable/shape_miaosha_time"
   android:gravity="center"
   android:text="1"
   android:textColor="#fff"
   android:textSize="15sp" />
  </LinearLayout>
 </LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
 android:shape="rectangle">
 <solid android:color="#000"></solid>
 <corners android:radius="2.5dp"></corners>
</shape>

方法內(nèi)容:

//得到控件
 mMiaoshaShiTv = view.findViewById(R.id.tv_miaosha_shi);
 mMiaoshaTimeTv = view.findViewById(R.id.tv_miaosha_time);
 mMiaoshaMinterTv = view.findViewById(R.id.tv_miaosha_minter);
 mMiaoshaSecondTv = view.findViewById(R.id.tv_miaosha_second);



 /****************京東秒殺倒計時**********************/

 //使用handler用于更新UI
 private Handler handler = new Handler() {
 @Override
 public void handleMessage(Message msg) {
  super.handleMessage(msg);
  countDown();
  handler.sendEmptyMessageDelayed(0, 1000);
 }
 };

 /**
 * 秒殺
 */
 private void countDown() {
 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) {
  mMiaoshaTimeTv.setText(hour + "點場");
  buffer.append((hour + 2));
  buffer.append(":00:00");
 } else {
  mMiaoshaTimeTv.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);
  mMiaoshaShiTv.setText("0" + hours + "");
  if (minute >= 10) {
  mMiaoshaMinterTv.setText(minute + "");
  } else {
  mMiaoshaMinterTv.setText("0" + minute + "");
  }
  if (second >= 10) {
  mMiaoshaSecondTv.setText(second + "");
  } else {
  mMiaoshaSecondTv.setText("0" + second + "");
  }
 } catch (ParseException e) {
  e.printStackTrace();
 }
 }

 /***************京東秒殺倒計時****************/


開啟倒計時:

handler.sendEmptyMessage(0);

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • Android游戲之數(shù)獨游戲開發(fā)

    Android游戲之數(shù)獨游戲開發(fā)

    這篇文章主要為大家詳細介紹了Android游戲之數(shù)獨游戲開發(fā)的相關資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • Android中懸浮窗口的實現(xiàn)原理實例分析

    Android中懸浮窗口的實現(xiàn)原理實例分析

    這篇文章主要介紹了Android中懸浮窗口的實現(xiàn)原理,以實例形式較為詳細的分析了Android懸浮窗口的原理與具體實現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-10-10
  • Android多渠道打包神器ProductFlavor詳解

    Android多渠道打包神器ProductFlavor詳解

    最近一直在學習Android Gradle 相關的知識點,今天剛好看到了 ProductFlavor 這節(jié),ProductFlavor 的出現(xiàn)非常友好的幫助我們開發(fā)者解決了版本區(qū)分的問題
    2022-07-07
  • Android中傳值Intent與Bundle的區(qū)別小結(jié)

    Android中傳值Intent與Bundle的區(qū)別小結(jié)

    這篇文章主要給大家總結(jié)介紹了關于Android中傳值Intent與Bundle的區(qū)別,文中通過示例代碼以及圖文介紹的非常詳細,對各位Android開發(fā)者們具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧
    2019-03-03
  • Android實現(xiàn)帶有指示器的進度條

    Android實現(xiàn)帶有指示器的進度條

    這篇文章主要介紹了Android實現(xiàn)帶有指示器的進度條的示例代碼,幫助大家更好的理解和學習使用Android開發(fā),感興趣的朋友可以了解下
    2021-05-05
  • MotionLayout自定義開關按鈕實例詳解

    MotionLayout自定義開關按鈕實例詳解

    這篇文章主要為大家介紹了MotionLayout自定義開關按鈕實例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-11-11
  • Android自定義ViewGroup實現(xiàn)側(cè)滑菜單

    Android自定義ViewGroup實現(xiàn)側(cè)滑菜單

    這篇文章主要為大家詳細介紹了Android如何通過自定義ViewGroup實現(xiàn)側(cè)滑菜單,文中的示例代碼講解詳細,感興趣的小伙伴可以了解一下
    2023-01-01
  • Kotlin WorkManager使用方法詳解

    Kotlin WorkManager使用方法詳解

    這篇文章主要介紹了Kotlin WorkManager使用方法,WorkManager是 安卓體系結(jié)構之一,也是Android JetPack的一部分。WorkManager用于可延期并需要保證執(zhí)行的后臺工作
    2023-01-01
  • 詳解Android中Notification的使用方法

    詳解Android中Notification的使用方法

    這篇文章主要介紹了Android中Notification的使用方法,最典型的應用就是未看短信和未接來電的顯示,還有QQ微信,想要深入了解Notification的朋友可以參考本文
    2015-12-12
  • Android Studio如何快速導入jar和.so文件

    Android Studio如何快速導入jar和.so文件

    這篇文章主要介紹了Android Studio如何快速導入jar和.so文件的相關知識,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2017-12-12

最新評論