亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android開屏頁(yè)倒計(jì)時(shí)功能實(shí)現(xiàn)的詳細(xì)教程

 更新時(shí)間:2017年06月07日 16:48:26   作者:KeithXiaoY  
本篇文章主要介紹了Android實(shí)現(xiàn)開屏頁(yè)倒計(jì)時(shí)功能實(shí)現(xiàn)的詳細(xì)教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

最近我司產(chǎn)品提出了一個(gè)很常見的需求:App 在開屏頁(yè)(Splash 界面) 需要加上一個(gè) 3s 倒計(jì)時(shí)按鈕,可以選擇看 3s 的廣告,或者點(diǎn)擊按鈕跳過廣告。


一、布局實(shí)現(xiàn)(使用 FrameLayout 懸浮在廣告的右上角,顯示倒計(jì)時(shí)的 TextView 的寬高盡量不要寫死,要考慮字體很多的情況!!)

  <FrameLayout
    android:id="@+id/start_skip"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true">

    <TextView
      android:id="@+id/start_skip_count_down"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_margin="@dimen/default_padding"
      android:text="@string/click_to_skip"
      android:gravity="center"
      android:background="@drawable/bg_start_page_circle"
      android:textColor="@android:color/white"
      android:textSize="14sp"
      />
  </FrameLayout>

二、TextView 背景的 @drawable/bg_start_page_circle 用系統(tǒng) shape 實(shí)現(xiàn),不需要 UI 幫我們切圖

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

  <solid android:color="#80000000"/>

  <padding
    android:bottom="3dp"
    android:left="8dp"
    android:right="8dp"
    android:top="3dp"/>

  <corners
    android:bottomLeftRadius="45dp"
    android:bottomRightRadius="45dp"
    android:topLeftRadius="45dp"
    android:topRightRadius="45dp"/>

</shape>

三、在 onCreate() 里面找到顯示倒計(jì)時(shí)的 TextView

  private TextView mCountDownTextView;
 /**
   * Created by KeithXiaoY on 2017/06/07.
   */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    mCountDownTextView = (TextView) findViewById(R.id.start_skip_count_down);
  }

四、倒計(jì)時(shí)實(shí)現(xiàn)(使用 Android 系統(tǒng)原生的倒計(jì)時(shí)控件 CountDownTimer 實(shí)現(xiàn))

  class MyCountDownTimer extends CountDownTimer {
    /**
     * @param millisInFuture
     *   表示以「 毫秒 」為單位倒計(jì)時(shí)的總數(shù)
     *   例如 millisInFuture = 1000 表示1秒
     *
     * @param countDownInterval
     *   表示 間隔 多少微秒 調(diào)用一次 onTick()
     *   例如: countDownInterval = 1000 ; 表示每 1000 毫秒調(diào)用一次 onTick()
     *
     */

    public MyCountDownTimer(long millisInFuture, long countDownInterval) {
      super(millisInFuture, countDownInterval);
    }


    public void onFinish() {
      mCountDownTextView.setText("0s 跳過");
    }

    public void onTick(long millisUntilFinished) {
      mCountDownTextView.setText( millisUntilFinished / 1000 + "s 跳過");
    }

  }

五、根據(jù)具體的業(yè)務(wù)邏輯完整實(shí)現(xiàn)

  private TextView mCountDownTextView;
  private MyCountDownTimer mCountDownTimer;
 /**
   * Created by KeithXiaoY on 2017/06/07.
   */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    ...
    mCountDownTextView = (TextView) findViewById(R.id.start_skip_count_down);
      //我司需求,在沒有 Banner 廣告的時(shí)候一秒跳過開屏頁(yè),有 Banner 廣告的時(shí)候三秒跳過
    if (PreferencesFactory.getCommonPref().getBoolean(CommonPreferences.PREFS_HAS_START_PAGE_BANNER, false)) {
      mCountDownTextView.setText("3s 跳過");
      //創(chuàng)建倒計(jì)時(shí)類
      mCountDownTimer = new MyCountDownTimer(3000, 1000);
      mCountDownTimer.start();
      //這是一個(gè) Handler 里面的邏輯是從 Splash 界面跳轉(zhuǎn)到 Main 界面,這里的邏輯每個(gè)公司基本上一致
      tmpHandler.postDelayed(runnable, 3000);
    } else {
      mCountDownTextView.setText("1s 跳過");
      mCountDownTimer = new MyCountDownTimer(1000, 1000);
      mCountDownTimer.start();
      tmpHandler.postDelayed(runnable, 1000);
    }
  }

六、注意事項(xiàng)(一定記得在界面銷毀的時(shí)候?qū)?CountDownTimer 銷毀)

  @Override
  protected void onDestroy() {
    if (mCountDownTimer != null) {
      mCountDownTimer.cancel();
    }
    super.onDestroy();
  }

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

相關(guān)文章

最新評(píng)論