【Android 开发教程】AnalogClock和DigitalClock

来源:互联网 发布:黑龙江网络干部 编辑:程序博客网 时间:2024/04/29 23:01

本章节翻译自《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文件中就可以了。

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:orientation="vertical" >  
  6.   
  7.     <AnalogClock  
  8.         android:layout_width="wrap_content"  
  9.         android:layout_height="wrap_content" />  
  10.   
  11.     <DigitalClock  
  12.         android:layout_width="wrap_content"  
  13.         android:layout_height="wrap_content" />  
  14.   
  15. </LinearLayout>  



0 0
原创粉丝点击