1.首先创建一个kotlin项目
2.在module下的build.gradle引入
//带动画效果的时间减少 implementation 'com.sfyc.ctpv:library:1.1.3'
3.在布局文件中添加布局
<com.sfyc.ctpv.CountTimeProgressView
android:id="@+id/pv_count_time"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_marginTop="20dp"
android:layout_marginRight="10dp"
app:backgroundColorCenter="@android:color/transparent"
app:borderBottomColor="@android:color/darker_gray"
app:borderDrawColor="#7C49F2"
app:borderWidth="2dp"
app:clockwise="true"
app:countTime="10000"
app:textStyle="second"
app:titleCenterColor="#FF222222"
app:titleCenterSize="13sp" />
app:countTime:倒计时开始时间,单位毫秒
4.在activity中代码
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//结束时间
pv_count_time.startAngle = 0f
//开始递减动画
pv_count_time.startCountTimeAnimation()
//时间递减监听事件
pv_count_time.addOnEndListener(object : CountTimeProgressView.OnEndListener {
override fun onAnimationEnd() {
Toast.makeText([email protected], "倒计时结束", Toast.LENGTH_SHORT).show()
}
override fun onClick(l: Long) {
Toast.makeText([email protected], "点击事件", Toast.LENGTH_SHORT).show()
}
})
}
5.效果图