直播平台搭建,计时和倒计时功能的分别实现
作者:互联网
直播平台搭建,计时和倒计时功能的分别实现
一、计时功能:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:gravity="center"
tools:context=".ChronometerActivity">
<Chronometer
android:id="@+id/chronometer"
android:layout_width="200dp"
android:layout_height="200dp"
android:gravity="center"/>
</LinearLayout>
public class ChronometerActivity extends AppCompatActivity {
private static final String TAG = "ChronometerActivity";
private Chronometer chronometer;
int count=60;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chronometer);
chronometer=(Chronometer)findViewById(R.id.chronometer);
chronometer.start();
//停止计时
//chronometer.stop();
}
}
二、倒计时功能:
public class ChronometerActivity extends AppCompatActivity {
private static final String TAG = "ChronometerActivity";
private Chronometer chronometer;
int count = 60;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chronometer);
chronometer = (Chronometer) findViewById(R.id.chronometer);
chronometer.start();
//停止计时
//chronometer.stop();
chronometer.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener() {
@Override
public void onChronometerTick(Chronometer chronometer) {
count--;
chronometer.setText(count + "");
if (count == 0) {
chronometer.stop();
}
}
});
}
}
以上就是直播平台搭建,计时和倒计时功能的分别实现, 更多内容欢迎关注之后的文章
标签:count,layout,chronometer,倒计时,直播,ChronometerActivity,计时,android,Chronometer 来源: https://www.cnblogs.com/yunbaomengnan/p/16466253.html