Create simple AnalogClock in android example tutorial

How to show analog clock inside android application with current mobile time.

In this tutorial we are creating a simple analog clock using AnalogClock widget in android application. Analog clock has three moving hands one for hour, second for minutes and third one for seconds. So here is the complete step by step tutorial for Create simple AnalogClock in android example tutorial.

android-project-download-code-button

How to Create simple AnalogClock in android example tutorial.

Code for MainActivity.java file.

 package com.analogclock_android_examples.com;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 }
}

Code for activity_main.xml layout file.

 <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:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.analogclock_android_examples.com.MainActivity" >

 <AnalogClock
 android:id="@+id/analogClock1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true" />

</RelativeLayout>

Screenshot:

Create simple AnalogClock in android example tutorial

Click here to download Create simple AnalogClock in android example tutorial project with source code.

Leave a Reply

Your email address will not be published. Required fields are marked *