基于第三方的倒计时控件

1、加依赖

compile 'com.github.iwgang:countdownview:1.2'
2、在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"
    tools:context="com.bruce.time.MainActivity">

    <cn.iwgang.countdownview.CountdownView
        android:id="@+id/cv_countdownViewTest1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:isHideTimeBackground="true"
        app:isShowDay="true"
        app:isShowHour="true"
        app:isShowMillisecond="true"
        app:isShowMinute="true"
        app:isShowSecond="true"
        app:isTimeTextBold="true"
        app:suffixDay="天"
        app:suffixGravity="bottom"
        app:suffixHour="时"
        app:suffixMillisecond="毫秒"
        app:suffixMinute="分"
        app:suffixSecond="秒"
        app:suffixTextColor="#000000"
        app:suffixTextSize="12sp"
        app:timeTextColor="#000000"
        app:timeTextSize="22sp"/>
</RelativeLayout>
3、java代码中设置

package com.bruce.time;

import android.app.Activity;
import android.os.Bundle;

import cn.iwgang.countdownview.CountdownView;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initWidget();
    }

    private void initWidget() {
        CountdownView mCvCountdownView = (CountdownView) findViewById(R.id.cv_countdownViewTest1);
        //倒计时1分钟-60秒*1000=60000millisecond
        mCvCountdownView.start(60000); // Millisecond

// or
        for (int time = 0; time < 1000; time++) {
            mCvCountdownView.updateShow(time);
        }
    }
}
第三方原地址:

https://github.com/iwgang/CountdownView


你可能感兴趣的:(基于第三方的倒计时控件)