Android用户界面 UI组件--TextView及其子类(四) Chronometer计时器
Chronometer是一个简单的定时器,你可以给它一个开始时间,并以此定时,或者如果你不给它一个开始时间,它将会使用你的时间通话开始。默认情况下它会显示在当前定时器的值的形式“分:秒”或“H:MM:SS的”,或者可以使用的Set(字符串)格式的定时器值到一个任意字符串
1.重要属性
android:format:定义时间的格式如:hh:mm:ss
2.重要方法
setBase(long base):设置倒计时定时器
setFormat(String format):设置显示时间的格式。
start():开始计时
stop():停止计时
setOnChronometerTickListener(Chronometer.OnChronometerTickListener listener):当计时器改变时调用
实例:
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:gravity="center_horizontal"
- android:orientation="vertical" >
- <Chronometer
- android:id="@+id/chronometer"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textColor="#ffff0000"
- android:textSize="12pt" />
- <Button
- android:id="@+id/start"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:onClick="onClick"
- android:text="启动" />
- <Button
- android:id="@+id/stop"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:onClick="onClick"
- android:text="停止" />
- <Button
- android:id="@+id/reset"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:onClick="onClick"
- android:text="复位" />
- </LinearLayout>
- package com.light.study.android;
- import android.app.Activity;
- import android.os.Bundle;
- import android.os.SystemClock;
- import android.view.View;
- import android.widget.Button;
- import android.widget.Chronometer;
- public class MainActivity extends Activity {
- private Button startBtn,stopBtn,resetBtn;
- private Chronometer chronomete;
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- chronomete = (Chronometer) this.findViewById(R.id.chronometer);
- startBtn = (Button) this.findViewById(R.id.start);
- stopBtn = (Button) this.findViewById(R.id.stop);
- resetBtn = (Button) this.findViewById(R.id.reset);
- }
- public void onClick(View v) {
- if (v == startBtn) {// 开始计时
- chronomete.start();
- } else if (v == stopBtn) {
- chronomete.stop();// 停止计时
- } else if (v == resetBtn) {
- chronomete.setBase(SystemClock.elapsedRealtime());// 复位
- }
- }
- }
结果:
Android用户界面 UI组件--TextView及其子类(四) Chronometer计时器的更多相关文章
- Android用户界面 UI组件--TextView及其子类(二) Button,selector选择器,sharp属性
1.XML文件中的OnClick 属性可以指定在Activity中处理点击事件的方法,Activity中必须定义该属性指定的值作为方法的名字且有一个View类型的参数,表示此物件被点击. 2.使用se ...
- Android用户界面 UI组件--TextView及其子类(三) EditView以及各种Span文字样式讲解
EditView和TextView的用法差不多,只是文字可编辑 小技巧: 设置EditText隐藏键盘 setInputType(0); 设置EditText不被输入法遮盖 getWindow() ...
- Android用户界面 UI组件--TextView及其子类(一) TextView
1.TextView android:autoLink设置是否当文本为URL链接/email/电话号码/map时,文本显示为可点击的链接.可选值(none /web/email/phone/map/a ...
- Android用户界面UI组件--AdapterView及其子类(四) GridView
GridView常用的XML属性: android:columnWidth 设置列的宽度. android:horizontalSpacing 两列之间的间距. android:numColum ...
- Android用户界面 UI组件--TextView及其子类(五) DigitalClock,AnalogClock,RadioButton,CheckBox,ToggleButton汇总
DigitalClock和AnalogClock两个时钟类 可以为DigitalClock设置背景图片,自定义时针,秒针,分针的样式 例子: <?xml version="1.0&qu ...
- Android用户界面 UI组件--AdapterView及其子类(一) ListView及各种Adapter详解
ListView就是列表组件,一般通过继承ListActivity使用系统提供的ListView. 所有的AdapterView组件都需要有一个对应的Adapter作为适配器来显示列表中元素的布局方式 ...
- Android用户界面UI组件--AdapterView及其子类(五) Spinner和SpinnerAdapter
Spinner就是下拉框组件,可以自定义下拉布局样式,可以使用ArrayAdapter以及SpinnerAdapter适配 在Adapter中实现SpinnerAdapter,继承BaseAdapte ...
- Android用户界面UI组件--AdapterView及其子类(三) ExpandableListView
ExpandableListView: List中的每一项可以展开收缩. 一种伸缩式的ListView. android:cacheColorHint="#00000000" 这个 ...
- Android用户界面 UI组件--ImageView及其子类ImageButton,QuickContactBadge附带Draw9Patch工具说明
1.ImageView 常用属性: android:src 设置可绘制对象作为 ImageView 显示的内容 android:cropToPadding 如果设置为true,图片裁剪到保留该Imag ...
随机推荐
- Unity3D 之3D游戏SD快打 3D游戏基础入门开发全(1)
这里记录一个U3D游戏,3D游戏的基本开发. 导入素材 1.首先导入需要的素材.因为FBX格式的素材是通用的,所以尽量导入这样的资源使用 导入后的结果: 然后对人形骨骼进行设置. 看哪里没有映射到骨骼 ...
- jQuery Validation Plugin学习
http://blog.csdn.net/violet_day/article/details/14109261 jQuery Validation Plugin Demo 一.默认校验规则 (1)r ...
- 16Aspx.com源码2013年10月到2013年12月详细
创建时间FROM: 创建时间TO: ExtJS合同管理信息系统源码 2013-12-13 [VS2008] 源码介绍: ExtJS合同管理信息系统源码浏览器兼容:IE,Firefox,谷歌等主 ...
- 20151212Jquery 工具函数代码备份
$(function () { /*var str=' jquery '; alert(str); alert($.trim(str));*/ /*var arr=['张三','李四','王五','麻 ...
- Service解析
Service解析: 运行service有如下两种方式: StartService() 访问者退出,service仍然运行: BindService() 访问者与service绑定,访问者退出,ser ...
- ACM——进制转换
http://acm.njupt.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1012 进制转换 时间限制(普通/Jav ...
- Power Map 更新日志
2015-05-18,五月更新 Custom Regions feature,允许用户自定义区域要素,支持kml和shape格式 New customization features,包括图例/文本框 ...
- Codevs 2597 团伙(并查集)
2597 团伙 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 传送门 题目描述 Description 1920年的芝加哥,出现了一群强盗.如果两个强盗遇上了,那么 ...
- leetcode344——Reverse String(C++)
Write a function that takes a string as input and returns the string reversed. Example:Given s = &qu ...
- 【转】Vim命令合集以及乱码问题解决
乱码问题 """""""""""""""" ...