在android如果表示数字时针一般用DigitalClock,这个类是google给我们开发者提供的一个方便的类实现数字时针的功能,现在就写个demo,为什么要讲这个类呢?因为我下篇要讲ListView item倒计时功能,所以先把这个基础练习一下,以及它的实现方式,新建android项目digitalClockdemo
布局activity_main.xml文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<DigitalClock android:id="@+id/digitalClock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="25sp"
android:textColor="#ff00ff"
/>
</RelativeLayout>
代码都不用写 直接运行起来就会有效果
这个数字是变化的 这只是静态图,为什么代码没写会出来这个效果,所以就得看下他的源码了
public class DigitalClock extends TextView {
Calendar