本章节翻译自《Beginning-Android-4-Application-Development》,如有翻译不当的地方,敬请指出。
原书购买地址http://www.amazon.com/Beginning-Android-4-Application-Development/dp/1118199545/AnalogClock视图显示了一个模拟的时钟,其中有一个时针和一个分针。与其相对的是DigitalClock视图,它可以显示数字模拟时钟。这两个视图只能显示系统时间,不允许显示一个特定时区的时间。因此,如果你想要显示一个特定时区的时间,那么你就不得不去实现你自己的自定义控件了。
注:关于如何自定义控件,请查看如下网址。
http://developer.android.com/guide/topics/ui/custom-components.html
使用AnalogClock与DigitalClock是非常简单的。只要把它们声明在xml文件中就可以了。
<?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:orientation="vertical" >
<AnalogClock
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<DigitalClock
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>