First, the basic definition
AnalogClock and DigitalClock are two very simple components, and DigitalClock itself is a text box, except that the content shown in it is time, but the Android:text attribute of DigitalClock doesn't work. The AnalogClock inherits the view component, overrides the view's OnDraw method, and draws the analog clock on the view.
Second, the attribute
A description of the XML attributes supported by AnalogClock.
| XML properties |
Description |
| Android:dial |
Set the picture used for the analog clock's dial |
| Android:hand_hour |
Set the analog clock to the hour dial using the picture |
| Android:hand_minute |
Set the hand image of the analog clock with the minute hand |
Third, the realization effectIv. The process of writing
AnalogClock and DigitalClock are relatively simple to write, simply put the appropriate controls in the XML file, and reference the relevant picture based on the attribute.
1. Create a new DigitalClock control in the XML file.
1 <2 android:id= "@+id/digitalclock"3 android:layout_width= "Wrap_ Content "4 android:layout_height=" Wrap_content "5 android:textsize=" 30SP "6 android:isscrollcontainer= "true"/>
View Code
2. Create a new AnalogClock control. The Dial property controls the dial style, found through "@Drawable/Picture", Hand_hour and minute control pointer styles, found through "@Drawable/pictures".
1 <2 android:id= "@+id/analogclock"3 android:layout_width= "Wrap_ Content "4 android:layout_height=" Wrap_content "5 android:dial=" @drawable/watch "6 android:hand_hour= "@drawable/hand"7 android:hand_minute= "@drawable/hand"/>
View CodeFive, source code
XML file, other code does not change
1<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"2Xmlns:tools= "Http://schemas.android.com/tools"3Android:layout_width= "Match_parent"4android:layout_height= "Match_parent"5android:orientation= "Vertical"6Tools:context= ". Mainactivity ">7 8<DigitalClock9Android:id= "@+id/digitalclock"TenAndroid:layout_width= "Wrap_content" Oneandroid:layout_height= "Wrap_content" AAndroid:textsize= "30SP" -Android:isscrollcontainer= "true"/> - the<AnalogClock -Android:id= "@+id/analogclock" -Android:layout_width= "Wrap_content" -android:layout_height= "Wrap_content" +Android:dial= "@drawable/watch" -Android:hand_hour= "@drawable/hand" +Android:hand_minute= "@drawable/hand"/> A at</LinearLayout>
View Code
Android Learning notes _s01_e02 AnalogClock and DigitalClock (clock) features and usage