android自定义倒计时控件示例
import com.new0315.R;/** * 自定义倒计时文本控件 * @author Administrator * */public class TimeTextView extends TextView implements Runnable{
Paint mPaint; //画笔,包含了画几何图形、文本等的样式和颜色信息
private long[] times;
private long mday, mhour, mmin, msecond;//天,小时,分钟,秒
private boolean run=false; //是否启动了
public TimeTextView(Context context, AttributeSet attrs) { super(context, attrs); mPaint=new Paint(); TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.TimeTextView);
array.recycle(); //一定要调用,否则这次的设定会对下次的使用造成影响 }
public TimeTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mPaint=new Paint(); TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.TimeTextView);
array.recycle(); //一定要调用,否则这次的设定会对下次的使用造成影响 }
public TimeTextView(Context context) { super(context); }
public long[] getTimes() { return times; }
public void setTimes(long[] times) { this.times = times; mday = times[0]; mhour = times[1]; mmin = times[2]; msecond = times[3];
}
/** * 倒计时计算 */ private void ComputeTime() { msecond--; if (msecond < 0) { mmin--; msecond = 59; if (mmin < 0) { mmin = 59; mhour--; if (mhour < 0) { // 倒计时结束 mhour = 59; mday--;
} }
}
}
public boolean isRun() { return run; }
public void setRun(boolean run) { this.run = run; }
@Override public void run() { //标示已经启动 run=true;
ComputeTime();
String strTime="还剩</pre><span style="color: red;">"+mday+"</span><pre>"+"天</pre><span style="color: red;">"+mhour+"</span><pre>小时</pre><span style="color: red;">"+ mmin+"</span><pre>分钟</pre><span style="color: red;">"+msecond+"</span><pre>秒"; this.setText(Html.fromHtml(strTime));
postDelayed(this, 1000);
}
}
- android自定义倒计时控件示例
- android自定义倒计时控件示例
- android自定义控件以及复用控件示例详解
- 浅谈Android RecyclerView UI的滚动控件示例
- Android自定义折线图控件示例
- android gallery 画廊控件示例
- Android控件Tween动画(补间动画)实现方法示例
- Android自定义组合控件详细示例 (附完整源码)
- Android AutoCompleteTextView控件基本用法示例
- Android布局整合include界面控件 示例
- Android自定义倒计时控件
- android studio StackView控件的源码解释和简单示例
- Android自定义倒计时控件
- Android 图片网格布局控件示例代码
- Android示例-JavaScript与UI控件交互(二)
- Android基于widget组件实现物体移动/控件拖动功能示例
- android基本控件示例两个Spinner下拉列表的关联(04)
- Android编程之下拉菜单Spinner控件用法示例
- android基本控件示例Spinner下拉列表(04)
- Android部分控件示例汇总