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

来源:互联网 发布:遗传算法例题 编辑:程序博客网 时间:2024/06/05 18:58

时钟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>

运行结果如下。



0 0
原创粉丝点击