Android Learning-Interface-ui-analogclock, DigitalClock and chronometer

Source: Internet
Author: User

AnalogClock traditional clock, digitalclock electronic clock, chronometer is a timer

Analogclockxml Property

XML properties Description
Android:dial Pictures used on the dial
Android:hand_hour Picture using the hour hand
Android:hand_minute Pictures used in minutes

Above is AnalogClock, which adds a picture of the dial

The following is DigitalClock

<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:orientation= "vertical" >    <AnalogClockAndroid:id= "@+id/analogclock1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:dial= "@drawable/b"        />     <DigitalClockAndroid:layout_width= "Wrap_content"Android:layout_height= "Match_parent" /></LinearLayout>

An example of a timer

XML code

<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:orientation= "vertical" >    <chronometerAndroid:id= "@+id/chronometer1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Chronometer" />    <ButtonAndroid:id= "@+id/button1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Start" />    <TextViewAndroid:id= "@+id/textview1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Large Text"android:textappearance= "? Android:attr/textappearancelarge" />    </LinearLayout>

Java code

 Public classMainactivityextendsActivity {chronometer chronometer1;        Button button1; protected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);            Setcontentview (R.layout.activity_main); Chronometer1=(chronometer) Findviewbyid (r.id.chronometer1); //Set FormatChronometer1.setformat ("Timer:%s"); Chronometer1.setonchronometerticklistener (NewOnchronometerticklistener () { Public voidonchronometertick (chronometer ch) {Message msg=NewMessage (); Bundle b=NewBundle (); //Current time-time to start timing = How much time was actually timedB.putstring ("Time", (Systemclock.elapsedrealtime ()-ch.getbase ())/1000+ ""); Msg.what=1111;                Msg.setdata (b);                Handler.sendmessage (msg); if((Systemclock.elapsedrealtime ()-ch.getbase ())/1000>=5) {Toast.maketext (Getapplicationcontext (),"Time is up.", Toast.length_short). Show ();                Ch.stop ();                }                            }        }); Button button1=(Button) Findviewbyid (R.id.button1); Button1.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {//Timing StartsChronometer1.start ();            }        }); } Handler Handler=NewHandler () {@Override Public voidhandlemessage (Message msg) {if(msg.what==1111) {TextView textView1=(TextView) Findviewbyid (R.ID.TEXTVIEW1); String Time= "Time obtained through message:" +msg.getdata (). GetString ("Times");            Textview1.settext (time);        }        }    }; }

Android Learning-Interface-ui-analogclock, DigitalClock and chronometer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.