您的位置:首页 > 其它

时钟(AnalogClock和TextClock)的功能和用法

2016-03-10 10:51 411 查看
时钟UI组件是两个非常简单的组件:TextClock本身就继承了TextView,也就是说,他本身就是文本框,只是他里面显示的内容总是当前的时间。

与TextView不用的是,为TextClock设置android:text属性没什么作用。

实例:手机里的“劳力士”。

界面布局文件如下。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.l2112.clocktest.MainActivity"
tools:showIn="@layout/activity_main"
android:orientation="vertical"
android:gravity="center_horizontal">
<!--定义模拟时钟-->
<AnalogClock
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!--定义数字时钟-->
<TextClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10pt"
android:textColor="#f0f"
android:format24Hour="yyyy年MM月dd日 H:mma EEEE"
/>
<!--定义模拟时钟,并使用自定义表盘、时针图片-->
<AnalogClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:dial="@drawable/watch"
android:hand_minute="@drawable/hand"/>
</LinearLayout>


运行结果如下。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: