Android如何實現(xiàn)京東秒殺界面-創(chuàng)新互聯(lián)

這篇文章主要介紹Android如何實現(xiàn)京東秒殺界面,文中介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們一定要看完!

創(chuàng)新互聯(lián)公司的客戶來自各行各業(yè),為了共同目標(biāo),我們在工作上密切配合,從創(chuàng)業(yè)型小企業(yè)到企事業(yè)單位,感謝他們對我們的要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團隊有機會用頭腦與智慧不斷的給客戶帶來驚喜。專業(yè)領(lǐng)域包括成都網(wǎng)站設(shè)計、成都網(wǎng)站制作、電商網(wǎng)站開發(fā)、微信營銷、系統(tǒng)平臺開發(fā)。

具體內(nèi)容如下

效果圖:

Android如何實現(xiàn)京東秒殺界面

京東秒殺是兩個小時一個場次,判斷本機的時間進行場次定時,然后在這兩個小時里面進行倒計時。

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(對倒計時小黑框圓角的實現(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>

以上是“Android如何實現(xiàn)京東秒殺界面”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

網(wǎng)站欄目:Android如何實現(xiàn)京東秒殺界面-創(chuàng)新互聯(lián)
當(dāng)前鏈接:http://bm7419.com/article6/dpohig.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化Google、網(wǎng)站設(shè)計網(wǎng)站收錄、商城網(wǎng)站、ChatGPT

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護公司