Android imitation keep sports rest countdown circular control

Imitation keep exercise rest countdown control for your reference. The specific contents are as follows

Source code

The control itself is very, very simple. The only difficulty lies in the dynamic increase and decrease duration during the countdown. If the dynamic increase and decrease duration is completed in an instant, it is not difficult to countdown. However, if it takes a certain time to do animation (see the effect drawing), there will be more logic to consider. This is also the purpose of writing this. The corresponding source code is the method of plus. Address: keepcountdownview

effect

usage method

xml:

<com.KeepCountdownView.KeepCountdownView
      android:id="@+id/keep1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      //各种可选属性
      app:arcColor="#FB5858"
      app:numColor="#7CB4EF"
      app:XXX/>

code:

 @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.keep_act);
    ButterKnife.bind(this);
    //倒计时监听
    keep1.setCountdownListener(new KeepCountdownView.CountdownListener() {
      @Override
      public void onStart() {
      }

      @Override
      public void onEnd() {

      }
    });
  }

  @OnClick(R.id.b1)
  public void b1(View v) {
    keep1.plus(5);//增加5s

  }

  @OnClick(R.id.b2)
  public void b2() {
    keep1.post(new Runnable() {
      @Override
      public void run() {
        keep1.startCountDown();//开始倒计时
      }
    });
  }

  @OnClick(R.id.b4)
  public void b4() {
    keep1.reset();//重置
  }

optional attribute

The above is the whole content of this article. I hope it will help you in your study, and I hope you will support us a lot.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>