Android_自定义控件_倒计时控件
来源:互联网 发布:js xml格式化显示代码 编辑:程序博客网 时间:2024/06/04 20:46
源码链接:https://github.com/chengbiao1314/View.git
思路分析:(这个自定义控件很简单)
1、自定义一个View集成TextView
2、子线程的开启 和停止
3、倒计时的计算
View的代码:
package view;import android.content.Context;import android.util.AttributeSet;import android.util.Log;import android.view.View;import android.widget.TextView;/** * Created by Ricky on 2016/10/11. */public class TimerTextView extends TextView implements Runnable{ private boolean isRun = false; private long secondCount = 60; public TimerTextView(Context context, AttributeSet attrs) { super(context, attrs); this.setFocusable(true); this.setClickable(true); this.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { if(!isRun){ beginRun(); } } }); } @Override public void run() { if(isRun){ Log.v("aa:","********************************** > " + Thread.currentThread().getName()); this.setText(ComputeTime()); postDelayed(this, 1000); }else { removeCallbacks(this); } } /** * 倒计时计算 */ private String ComputeTime() { String backTime = ""; secondCount--; if (secondCount <= 0) { backTime = "重新获取"; secondCount = 60; this.isRun = false; this.setFocusable(true); this.setClickable(true); }else{ backTime = secondCount + "秒"; } return backTime; } public void setSecondCount(long secondCount){ this.secondCount = secondCount; } public boolean isRun() { return isRun; } public void beginRun() { this.isRun = true; this.setFocusable(false); this.setClickable(false); run(); } public void stopRun(){ this.isRun = false; }}
0 0
- Android_自定义控件_倒计时控件
- Android_组合式控件_自定义属性
- 自定义控件----倒计时控件
- Android_自定义控件
- Android_自定义控件样式
- Android_自定义控件
- Android_自定义控件_HorizontalListView
- 自定义倒计时控件
- 自定义倒计时TextView控件
- Android自定义倒计时控件
- Android自定义倒计时控件
- 自定义倒计时控件
- 自定义倒计时控件
- Android自定义倒计时控件
- Android自定义控件 倒计时
- Android_自定义切换控件SwitchView
- Android_自定义控件简单入门
- android_自定义控件第一炮
- 注解处理器
- Windows-MatConvNet编译vl_imreadjpeg遇到的问题
- 面向对象封装,继承,多态(一)
- QQ密码,理解
- JSON语法简介 介绍 json
- Android_自定义控件_倒计时控件
- 私有构造函数的作用
- 如何获取签名.jks中的SHA1
- C#中out和ref之间的区别
- html5 检测浏览器是否支持新特性
- leetCode练习(64)
- LeetCode笔记:141. Linked List Cycle
- Linux环境下Python2.7
- 常用正则表达式