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

Android仿京東首頁(yè)秒殺倒計(jì)時(shí)

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

本文實(shí)例為大家分享了Android仿京東首頁(yè)秒殺倒計(jì)時(shí)的具體代碼,供大家參考,具體內(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點(diǎn)場(chǎng)"
   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);



 /****************京東秒殺倒計(jì)時(shí)**********************/

 //使用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 + "點(diǎn)場(chǎng)");
  buffer.append((hour + 2));
  buffer.append(":00:00");
 } else {
  mMiaoshaTimeTv.setText((hour - 1) + "點(diǎn)場(chǎng)");
  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();
 }
 }

 /***************京東秒殺倒計(jì)時(shí)****************/


開啟倒計(jì)時(shí):

handler.sendEmptyMessage(0);

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android游戲之?dāng)?shù)獨(dú)游戲開發(fā)

    Android游戲之?dāng)?shù)獨(dú)游戲開發(fā)

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

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

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

    Android多渠道打包神器ProductFlavor詳解

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

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

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

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

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

    MotionLayout自定義開關(guān)按鈕實(shí)例詳解

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

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

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

    Kotlin WorkManager使用方法詳解

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

    詳解Android中Notification的使用方法

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

    Android Studio如何快速導(dǎo)入jar和.so文件

    這篇文章主要介紹了Android Studio如何快速導(dǎo)入jar和.so文件的相關(guān)知識(shí),非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2017-12-12

最新評(píng)論