Android控制項開發之Chronometer

來源:互聯網
上載者:User

標籤:android   style   blog   http   io   ar   color   os   使用   

(轉自:http://blog.csdn.net/sun6255028/article/details/6688349)

Chronometr是一個簡單的定時器,你可以給它一個開始時間,並以此定時,或者如果你不給它一個開始時間,
它將會使用你的時間通話開始。預設情況下它會顯示在當前定時器的值得形式"分:秒" 或"MM:SS",
或者可以使用set(字串)的定時器值到一個任一字元串

重要屬性

1 android:format    定義時間的格式如: hh:mm:ss  

重要方法

1 setBase(long base)      //設定倒計時定時器  2 setFormat(String format)    //設定顯示時間的格式   3 start()             //開始計時  4 stop()              //停止計時  5                                 //當計時器改變時調用  6 setOnChronometerTickListener(Chronometer.OnChronometerTickListener listener) 

常式main.xml源碼

 1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    2     android:orientation="vertical"   3     android:layout_width="wrap_content"    4     android:layout_height="wrap_content">   5    6 <Chronometer   7     android:id="@+id/chronometer"    8     android:layout_width="wrap_content"   9     android:layout_height="wrap_content"/>  10   11     <LinearLayout   12         android:layout_width="wrap_content"   13         android:layout_height="wrap_content">  14       15         <Button   16             android:onClick="onStart"   17             android:text="開始計時"   18             android:layout_width="wrap_content"   19             android:layout_height="wrap_content"/>  20           21         <Button   22             android:onClick="onStop"   23             android:text="停止計時"   24             android:layout_width="wrap_content"   25             android:layout_height="wrap_content"/>  26           27         <Button   28             android:onClick="onReset"   29             android:text="重設"   30             android:layout_width="wrap_content"   31             android:layout_height="wrap_content"/>     32     </LinearLayout>  33 </LinearLayout> 

Java源碼

ackage com.sx.Chronometer;    import android.app.Activity;  import android.os.Bundle;  import android.os.SystemClock;  import android.view.View;  import android.widget.Chronometer;    public class ChronometerActivity extends Activity   {      private Chronometer chronometer = null;            /** Called when the activity is first created. */      @Override      public void onCreate(Bundle savedInstanceState)      {          super.onCreate(savedInstanceState);          setContentView(R.layout.main);                    chronometer = (Chronometer) findViewById(R.id.chronometer);          chronometer.setFormat("計時:%s");      }            public void onStart(View view)       {           chronometer.start();      }            public void onStop(View view)       {           chronometer.stop();      }            public void onReset(View view)      {           chronometer.setBase(SystemClock.elapsedRealtime());      }  }  

 

Android控制項開發之Chronometer(轉)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.