Kotlin实现动画形式的时间递减功能?
- 作者: 再看我我打爆你的光头
- 来源: 51数据库
- 2021-08-27
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(this@MainActivity, "倒计时结束", Toast.LENGTH_SHORT).show() } override fun onClick(l: Long) { Toast.makeText(this@MainActivity, "点击事件", Toast.LENGTH_SHORT).show() } }) }
5.效果图
?
?
推荐阅读
热点文章
android中Bitmap用法(显示,保存,缩放,旋转)实例分析
12
android 仿微信聊天气泡效果实现思路
1
Android的尺度,drawable-xxxxxxx
2
Codeforces Round #656 (Div. 3) (C、D题)
1
Android之handler异步消息处理机制解析
6
GridView中图片显示出现上下间距过大,左右图片显示类似瀑布流的问题
0
AsyncTask的简单使用
5
两个简单Fragment之间的通信(三种方式)
18
uboot修改设置boot参数命令
41
android中实现从相册中一次性获取多张图片与拍照,并将选中的图片显示出来
2