Introduction
This article explains analog and digital clocks in Android. Android Studio is used to create the sample.
An analog clock and digital clock displays the time from the current device.To display an analog or digital clock you need to drag and drop the analog and digital clock from the pallet. The analog and digital clock cannot change the time of the device; to do so you will use TimePicker and DatePicker.
Step 1
Create a project like this:

Step 2
Create an XML file and with this:
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- android:paddingBottom="@dimen/activity_vertical_margin"
- tools:context=".MainActivity"
- android:background="#b76e79">
- <TextView
- android:gravity="center"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Clocks"
- android:textStyle="bold"
- android:textSize="30dp"
- android:id="@+id/textView" />
- <AnalogClock
- android:gravity="center"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/analogClock"
- android:layout_marginTop="50dp"
- />
- <DigitalClock
- android:layout_centerInParent="true"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/digitalClock"
- android:layout_marginTop="100dp" />
- </RelativeLayout>

Comments
Join the conversation! Your thoughts help the community grow.