第40章、指针AnlogClock与数字DigitalClock时钟(从零开始学Android)

来源:互联网 发布:微信怎么在淘宝买东西 编辑:程序博客网 时间:2024/04/30 03:14

  时间分为指针和数字两种,如果Android应用中用到时钟,仅需要使用指针时钟AnlogClock与数字时钟DigitalClock即可,不需要编程。

  当然如果你对系统的默认显示效果不满意,譬如你想要一个带日期、时间的显示,另当别论。 

一、设计界面

  1、打开“res/layout/activity_main.xml”文件。

  从工具栏向activity拖出1个AnlogClock指针时钟与DigitalClock数字时钟。

  

  2、打开activity_main.xml文件。

  代码如下:

<LinearLayout     xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical" >    <DigitalClock        android:id="@+id/digitalClock1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="DigitalClock" />    <AnalogClock        android:id="@+id/analogClock1"        android:layout_width="wrap_content"        android:layout_height="wrap_content" /></LinearLayout>


二、运行效果

  不需要任何代码,现在你已经有两个时钟了:一个是指针式的;一个是数字式的。

  

原创粉丝点击