進階控制項【安卓6】——計時器(Chronometer)、標籤(TabHost)

來源:互聯網
上載者:User

標籤:lin   技術   spec   prot   繼承   end   ima   inflate   start   

 計時器(Chronometer)

方法

描述

public Chronometer(Context context)【構造方法】

建立Chronometer對象

public long getBase()

設定一個基準時間,可以通過完成

public void setFormat(String format)

設定顯示格式

public long getBase()

返回設定的基準時間

public String getFormat()

返回設定的顯示格式

public void start()

開始計時

public void stop()

停止計時

public void setOnChronometerTickListener(

Chronometer.OnChronometerTickListener listener)

設定計時改變的監聽事件

 

 

 

 

 

 

 

 

 

 

 

 

 

 

<Chronometer     android:id="@+id/chro"      android: layout_width="fill_parent"     android: layout_height="wrap_content"/><LinearLayout      android: layout_width="fill_parent"     android: layout_height="wrap_content">         <Button             android:id="@+id/CbtStart"             android: text="開始"             android: layout_width="wrap_content"              android: layout_height="wrap_content"              android:layout_weight="1"/>          <Button             android:id="@+id/CbtStop"             android: text="結束"             android: layout_width="wrap_content"              android: layout_height="wrap_content"              android:layout_weight="1"/></LinearLayout>
Chronometer 標籤(TabHost) 方式一:直接繼承 TabActivity

tab.xml

 1 public class Tabhost extends TabActivity { 2    protected void onCreate(Bundle savedInstanceState) { 3        super.onCreate(savedInstanceState); 4        TabHost tab=getTabHost();        //取得TabHost類的對象 5        LayoutInflater . from (this). 6             inflate(R.layout.tab,        //定義轉換的布局管理器 7             tab.getTabContentView(),    //指定標籤增加的容器 8                 true);                //執行個體化布局管理器中的組件 9       //選項10        TabSpec sp1=tab.newTabSpec ("tab1");11         //設定標籤的標題,設定標籤的顯示內容12        sp1.setIndicator("選項1").setContent (R.id.Ttv01);    13        tab.addTab(sp1);    //設定標籤的tab14         15        TabSpec sp2=tab.newTabSpec ("tab2");16        sp2.setIndicator("選項2").setContent (R.id.Ttv02);17        tab.addTab (sp2);18         19        TabSpec sp3=tab.newTabSpec ("tab3");20        sp3.setIndicator("選項3").setContent (R.id.Ttv03);21        tab.addTab (sp3);22     }23 }
標籤控制項:程式碼範例

TabHost.TabSpec

    TabHost類增加每一個選項需要增加多個TabHost.TabSpec的對象,

    此類事TabHost定義的內部類

 

方式二:在布局檔案中定義組件

    使用<TabHost>標籤做根標籤

 

<TabHostxmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="wrap_content"  android:layout_height="wrap_content">  <LinearLayout        android:id="@+id/Tll01"      android:layout_width="fill_parent"      android:layout_height="fill_parent">            <ImageView                android:src="@drawable/a"              android:layout_width="wrap_content"              android:layout_height="wrap_content"/>          <TextView              android:text="哈哈哈"              android:layout_width="wrap_content"              android:layout_height="wrap_content"/>  </LinearLayout>  <LinearLayout        android:id="@+id/Tll02"        android:orientation="vertical"      android:layout_width="fill_parent"      android:layout_height="fill_parent">            <ImageView                android:src="@drawable/b"              android:layout_width="wrap_content"              android:layout_height="wrap_content"/>          <TextView              android:text="哈哈哈"              android:layout_width="wrap_content"              android:layout_height="wrap_content"/>  </LinearLayout></TabHost>
標籤控制項:xml代碼
 1 protected void onCreate(Bundle savedInstanceState) { 2     super.onCreate(savedInstanceState); 3     TabHost tab=getTabHost(); 4     LayoutInflater.from(this). 5         inflate(R.layout.tab0,        //定義轉換的布局管理器 6         tab.getTabContentView(),    //指定標籤增加的容器 7         true);                //執行個體化布局管理器中的組件 8     //選項 9     TabSpec sp1=tab.newTabSpec("tab1");10     //設定標籤的標題,設定標籤的顯示內容11     sp1.setIndicator("選項1").setContent(R.id.Tll01);    12     tab.addTab(sp1);    //設定標籤的tab13         14     TabSpec sp2=tab.newTabSpec("tab2");15     sp2.setIndicator("選項2").setContent(R.id.Tll02);16     tab.addTab(sp2);17 }
標籤控制項:java代碼

 

進階控制項【安卓6】——計時器(Chronometer)、標籤(TabHost)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.