Книга: Beginning Android

Time Keeps Flowing Like a River

Time Keeps Flowing Like a River

If you want to display the time, rather than have users enter the time, you may wish to use the DigitalClock or AnalogClock widgets. These are extremely easy to use, as they automatically update with the passage of time. All you need to do is put them in your layout and let them do their thing.

For example, from the Fancy/Clocks sample application, here is an XML layout containing both DigitalClock and AnalogClock:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
>
 <AnalogClock android:id="@+id/analog"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:layout_centerHorizontal="true"
  android:layout_alignParentTop="true"
 />
 <DigitalClock android:id="@+id/digital"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_centerHorizontal="true"
  android:layout_below="@id/analog"
 />
</RelativeLayout>

Without any Java code other than the generated stub, we can build this project (see Figure 10-4).


Figure 10-4. The ClocksDemo sample application

Оглавление книги


Генерация: 1.075. Запросов К БД/Cache: 3 / 1
поделиться
Вверх Вниз