绝大部分情况下,不需要使用者两个控件。即使要使用它们,也几乎无需针对它们进行编程。
1. 在布局文件 (main.xml) 中,增加界面元素声明如下:
<? xml version = "1.0" encoding = "utf-8" ?>
< LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:orientation = "vertical"
android:layout_width = "fill_parent"
android:layout_height = "fill_parent"
android:gravity = "center_horizontal"
>
< DigitalClock
android:id = "@+id/digital_clock"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
/>
< AnalogClock
android:id = "@+id/analog_clock"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
/>
</ LinearLayout >
运行结果 :