最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android實(shí)現(xiàn)京東秒殺界面

 更新時(shí)間:2018年04月18日 14:17:10   作者:l6666_6666  
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)京東秒殺界面,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android實(shí)現(xiàn)京東秒殺界面展示的具體代碼,供大家參考,具體內(nèi)容如下

效果圖:

京東秒殺是兩個(gè)小時(shí)一個(gè)場(chǎng)次,判斷本機(jī)的時(shí)間進(jìn)行場(chǎng)次定時(shí),然后在這兩個(gè)小時(shí)里面進(jìn)行倒計(jì)時(shí)。

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);
  }

  //秒殺倒計(jì)時(shí)
  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 + "點(diǎn)場(chǎng)");
      buffer.append((hour + 2));
      buffer.append(":00:00");
    } else {
      miaosha_time.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);
      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點(diǎn)場(chǎng)" />

    <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(對(duì)倒計(jì)時(shí)小黑框圓角的實(shí)現(xiàn))

<?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>

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

相關(guān)文章

  • Android仿微信主界面的實(shí)現(xiàn)方法

    Android仿微信主界面的實(shí)現(xiàn)方法

    這篇文章主要為大家詳細(xì)介紹了Android仿微信主界面的實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-04-04
  • Compose?的?Navigation組件使用示例詳解

    Compose?的?Navigation組件使用示例詳解

    這篇文章主要為大家介紹了Compose?的?Navigation組件使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-10-10
  • 詳解Android中PopupWindow在7.0后適配的解決

    詳解Android中PopupWindow在7.0后適配的解決

    本篇文章主要介紹了詳解Android中PopupWindow在7.0后適配的解決,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-05-05
  • android仿微信好友列表功能

    android仿微信好友列表功能

    這篇文章主要介紹了android仿微信好友列表功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2018-04-04
  • Android的搜索框架實(shí)例詳解

    Android的搜索框架實(shí)例詳解

    這篇文章主要介紹了Android的搜索框架實(shí)例詳解的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友一起看看吧
    2016-10-10
  • 基于Flutter制作一個(gè)心碎動(dòng)畫(huà)特效

    基于Flutter制作一個(gè)心碎動(dòng)畫(huà)特效

    這篇文章主要為大家介紹了如何利用Flutter制作一個(gè)心碎動(dòng)畫(huà)特效,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)Flutter有一定幫助,感興趣的可以了解一下
    2022-04-04
  • Android 新手入門(mén)體驗(yàn)

    Android 新手入門(mén)體驗(yàn)

    本篇文章小編為大家介紹,Android 新手入門(mén)體驗(yàn)。需要的朋友參考下
    2013-04-04
  • Flutter實(shí)現(xiàn)單選,復(fù)選和開(kāi)關(guān)組件的示例代碼

    Flutter實(shí)現(xiàn)單選,復(fù)選和開(kāi)關(guān)組件的示例代碼

    在App開(kāi)發(fā)過(guò)程中,選擇交互是非常常見(jiàn)的,今天主要介紹下關(guān)于選擇的三個(gè)組件的使用:開(kāi)關(guān)、單選和復(fù)選,感興趣的小伙伴可以了解一下
    2022-04-04
  • Android短信驗(yàn)證碼自動(dòng)填充功能

    Android短信驗(yàn)證碼自動(dòng)填充功能

    點(diǎn)擊獲取驗(yàn)證碼按鈕,收到短信,當(dāng)前應(yīng)用不需要退出程序就可以獲取到短信中的驗(yàn)證碼,并自動(dòng)填充,這篇文章主要介紹了Android短信驗(yàn)證碼自動(dòng)填充功能,感興趣的小伙伴們可以參考一下
    2016-08-08
  • Android Studio 實(shí)現(xiàn)九宮格功能

    Android Studio 實(shí)現(xiàn)九宮格功能

    這篇文章主要介紹了Android Studio 實(shí)現(xiàn)九宮格,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-04-04

最新評(píng)論

小金县| 临漳县| 皋兰县| 炎陵县| 青浦区| 梅河口市| 柳河县| 永仁县| 贵溪市| 延庆县| 仙居县| 深州市| 沾化县| 邵东县| 台南县| 水富县| 时尚| 漳州市| 府谷县| 修武县| 大足县| 黑河市| 无为县| 淮南市| 嘉兴市| 常熟市| 安溪县| 阿荣旗| 海林市| 丽水市| 墨江| 尉犁县| 内江市| 高州市| 阳春市| 桑植县| 祁东县| 阿拉善左旗| 句容市| 南平市| 西吉县|