最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android多功能時(shí)鐘開發(fā)案例(基礎(chǔ)篇)

 更新時(shí)間:2022年01月12日 07:59:46   投稿:lijiao  
這篇文章主要為大家詳細(xì)介紹了Android多功能時(shí)鐘開發(fā)案例的基礎(chǔ)知識(shí),為開發(fā)Android時(shí)鐘打下基礎(chǔ),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文我們進(jìn)入Android多功能時(shí)鐘開發(fā)實(shí)戰(zhàn)學(xué)習(xí),具體的效果可以參考手機(jī)上的時(shí)鐘,內(nèi)容如下

首先我們來看一看布局文件layout_main.xml

整個(gè)布局:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 android:id="@+id/container" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" > 
 
 <TabHost 
 android:id="@android:id/tabhost" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" > 
 
 <LinearLayout 
  android:layout_width="match_parent" 
  android:layout_height="match_parent" 
  android:orientation="vertical" > 
 
  <TabWidget 
  android:id="@android:id/tabs" 
  android:layout_width="match_parent" 
  android:layout_height="wrap_content" > 
  </TabWidget> 
 
  <FrameLayout 
  android:id="@android:id/tabcontent" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent" > 
 
  <com.example.clock.TimeView 
   android:id="@+id/tabTime" 
   android:layout_width="match_parent" 
   android:layout_height="match_parent" 
   android:orientation="vertical" > 
  </com.example.clock.TimeView> 
 
  <com.example.clock.AlarmView 
   android:id="@+id/tabAlarm" 
   android:layout_width="match_parent" 
   android:layout_height="match_parent" 
   android:orientation="vertical" > 
<span style="white-space:pre"> </span>…… 
  </com.example.clock.AlarmView> 
 
  <com.example.clock.TimerView 
   android:id="@+id/tabTimer" 
   android:layout_width="match_parent" 
   android:layout_height="match_parent" 
   android:orientation="vertical" > 
<span style="white-space:pre"> </span>…… 
  </com.example.clock.TimerView> 
 
  <com.example.clock.StopWatchView 
   android:id="@+id/tabStopWatch" 
   android:layout_width="match_parent" 
   android:layout_height="match_parent" 
   android:orientation="vertical" > 
<span style="white-space:pre"> </span>…… 
  </com.example.clock.StopWatchView> 
  </FrameLayout> 
 </LinearLayout> 
 </TabHost> 
 
</FrameLayout> 

 整個(gè)布局整的是一個(gè)FrameLayout,我們?cè)诶锩娣帕艘粋€(gè)TabHost,接下來我們就可以在里面直接添加自己想要的布局了,可能初學(xué)者初一看會(huì)有那么一個(gè)疑問,就是<com.example.clock.……></com.example.clock.……>這個(gè)是什么東西??這是一個(gè)自定義的控件,我們創(chuàng)建的一個(gè)繼承了LinearLayout的一個(gè)類(講解可以參考這里//m.fzitv.net/article/85515.htm),上面我們看到了四個(gè)這樣的標(biāo)簽,表示我們有四個(gè)這樣的Tab頁(yè)面。關(guān)于布局的東西這里就不多講了,之后會(huì)把我自己在學(xué)習(xí)過程中的一些不懂,以及相關(guān)的知識(shí)點(diǎn)上傳到資源中,大家可以下載來看看。

完整的布局文件代碼:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 android:id="@+id/container" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" > 
 
 <TabHost 
 android:id="@android:id/tabhost" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" > 
 
 <LinearLayout 
  android:layout_width="match_parent" 
  android:layout_height="match_parent" 
  android:orientation="vertical" > 
 
  <TabWidget 
  android:id="@android:id/tabs" 
  android:layout_width="match_parent" 
  android:layout_height="wrap_content" > 
  </TabWidget> 
 
  <FrameLayout 
  android:id="@android:id/tabcontent" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent" > 
 
  <com.example.clock.TimeView 
   android:id="@+id/tabTime" 
   android:layout_width="match_parent" 
   android:layout_height="match_parent" 
   android:orientation="vertical" > 
 
   <TextView 
   android:id="@+id/tvTime" 
   android:layout_width="fill_parent" 
   android:layout_height="fill_parent" 
   android:gravity="center" 
   android:textAppearance="?android:attr/textAppearanceLarge" /> 
  </com.example.clock.TimeView> 
 
  <com.example.clock.AlarmView 
   android:id="@+id/tabAlarm" 
   android:layout_width="match_parent" 
   android:layout_height="match_parent" 
   android:orientation="vertical" > 
 
   <ListView 
   android:id="@+id/lvListAlarm" 
   android:layout_width="fill_parent" 
   android:layout_height="0dp" 
   android:layout_weight="1" > 
   </ListView> 
 
   <Button 
   android:id="@+id/btnAddAlarm" 
   android:layout_width="fill_parent" 
   android:layout_height="wrap_content" 
   android:text="@string/add_alarm" > 
   </Button> 
  </com.example.clock.AlarmView> 
 
  <com.example.clock.TimerView 
   android:id="@+id/tabTimer" 
   android:layout_width="match_parent" 
   android:layout_height="match_parent" 
   android:orientation="vertical" > 
 
   <LinearLayout 
   android:layout_width="fill_parent" 
   android:layout_height="0dp" 
   android:layout_weight="1" 
   android:orientation="horizontal" > 
 
   <EditText 
    android:id="@+id/etHour" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:inputType="number" 
    android:singleLine="true" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 
 
   <TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text=":" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 
 
   <EditText 
    android:id="@+id/etMin" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:inputType="number" 
    android:singleLine="true" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 
 
   <TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text=":" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 
 
   <EditText 
    android:id="@+id/etSec" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:inputType="number" 
    android:singleLine="true" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 
   </LinearLayout> 
 
   <LinearLayout 
   android:id="@+id/btnGroup" 
   android:layout_width="fill_parent" 
   android:layout_height="wrap_content" 
   android:orientation="horizontal" > 
 
   <Button 
    android:id="@+id/btnStart" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="@string/start" /> 
 
   <Button 
    android:id="@+id/btnPause" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="@string/pause" /> 
 
   <Button 
    android:id="@+id/btnResume" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="@string/resume" /> 
 
   <Button 
    android:id="@+id/btnReset" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="@string/reset" /> 
   </LinearLayout> 
  </com.example.clock.TimerView> 
 
  <com.example.clock.StopWatchView 
   android:id="@+id/tabStopWatch" 
   android:layout_width="match_parent" 
   android:layout_height="match_parent" 
   android:orientation="vertical" > 
 
   <LinearLayout 
   android:layout_width="fill_parent" 
   android:layout_height="wrap_content" 
   android:orientation="horizontal" > 
 
   <TextView 
    android:id="@+id/timeHour" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 
 
   <TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text=":" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 
 
   <TextView 
    android:id="@+id/timeMin" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 
 
   <TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text=":" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 
 
   <TextView 
    android:id="@+id/timeSec" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 
 
   <TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="." 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 
 
   <TextView 
    android:id="@+id/timeMsec" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 
   </LinearLayout> 
 
   <ListView 
   android:id="@+id/lvWatchTime" 
   android:layout_width="fill_parent" 
   android:layout_height="0dp" 
   android:layout_weight="1" > 
   </ListView> 
 
   <LinearLayout 
   android:layout_width="fill_parent" 
   android:layout_height="wrap_content" 
   android:orientation="horizontal" > 
 
   <Button 
    android:id="@+id/btnSWStart" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="@string/start" /> 
 
   <Button 
    android:id="@+id/btnSWPause" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="@string/pause" /> 
 
   <Button 
    android:id="@+id/btnSWResume" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="@string/resume" /> 
 
   <Button 
    android:id="@+id/btnSWLap" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="@string/lap" /> 
 
   <Button 
    android:id="@+id/btnSWReset" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="@string/reset" /> 
   </LinearLayout> 
  </com.example.clock.StopWatchView> 
  </FrameLayout> 
 </LinearLayout> 
 </TabHost> 
 
</FrameLayout> 

講完了布局,我們來講講MainActivity

private TabHost tabHost; 
 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
 super.onCreate(savedInstanceState); 
 setContentView(R.layout.activity_main); 
 
 tabHost = (TabHost) findViewById(android.R.id.tabhost); 
 tabHost.setup(); 
 
 // 為TabHost添加標(biāo)簽 
 // 新建一個(gè)newTabSpec(newTabSpec)用來指定該標(biāo)簽的id(就是用來區(qū)分標(biāo)簽)的 
 // 設(shè)置其標(biāo)簽和圖表(setIndicator) 
 // 設(shè)置內(nèi)容(setContent) 
 /* 
 * 設(shè)置選項(xiàng)卡 : -- 設(shè)置按鈕名稱 : setIndicator(時(shí)鐘); -- 設(shè)置選項(xiàng)卡內(nèi)容 : setContent(), 
 * 可以設(shè)置視圖組件, 可以設(shè)置Activity, 也可以設(shè)置Fragement; 
 */ 
 tabHost.addTab(tabHost.newTabSpec("tabTime").setIndicator("時(shí)鐘") 
  .setContent(R.id.tabTime)); 
 tabHost.addTab(tabHost.newTabSpec("tabAlarm").setIndicator("鬧鐘") 
  .setContent(R.id.tabAlarm)); 
 tabHost.addTab(tabHost.newTabSpec("tabTimer").setIndicator("計(jì)時(shí)器") 
  .setContent(R.id.tabTimer)); 
 tabHost.addTab(tabHost.newTabSpec("tabStopWatch").setIndicator("秒表") 
  .setContent(R.id.tabStopWatch)); 
} 

在MainActivity中主要的操作就是設(shè)置TabHost,上面的代碼中已經(jīng)貼上了解釋,這里就不講了,接下來一篇我們就重點(diǎn)來講講時(shí)鐘、鬧鐘、計(jì)時(shí)器和秒表這四部分,希望大家繼續(xù)學(xué)習(xí)。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家學(xué)習(xí)Android軟件編程有所幫助。

相關(guān)文章

  • Android 知乎廣告效果實(shí)現(xiàn)代碼

    Android 知乎廣告效果實(shí)現(xiàn)代碼

    這篇文章主要介紹了Android 知乎廣告效果實(shí)現(xiàn)代碼,需要的朋友可以參考下
    2018-01-01
  • Ubuntu中為Android HAL編寫JNI方法提供JAVA訪問硬件服務(wù)接口

    Ubuntu中為Android HAL編寫JNI方法提供JAVA訪問硬件服務(wù)接口

    本文主要介紹Ubuntu中為Android硬件抽象層模塊編寫JNI方法提供Java訪問硬件服務(wù)接口,這里給大家詳細(xì)說明如何編寫 JNI方法訪問硬件接口并附示例代碼,有需要的小伙伴參考下
    2016-08-08
  • Google 開發(fā)Android MVP架構(gòu)Demo深入解析

    Google 開發(fā)Android MVP架構(gòu)Demo深入解析

    這篇文章主要為大家介紹了Google 開發(fā)Android MVP架構(gòu)Demo深入解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-11-11
  • Android仿微信鍵盤切換效果

    Android仿微信鍵盤切換效果

    這篇文章主要為大家詳細(xì)介紹了Android仿微信鍵盤切換效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-11-11
  • Android優(yōu)化方案之Fragment的懶加載實(shí)現(xiàn)代碼

    Android優(yōu)化方案之Fragment的懶加載實(shí)現(xiàn)代碼

    本篇文章主要介紹了Android優(yōu)化方案之Fragment的懶加載實(shí)現(xiàn)代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-03-03
  • android屏幕圓角實(shí)現(xiàn)方法的示例代碼

    android屏幕圓角實(shí)現(xiàn)方法的示例代碼

    本篇文章主要介紹了android屏幕圓角實(shí)現(xiàn)方法的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-11-11
  • android實(shí)現(xiàn)音樂播放器

    android實(shí)現(xiàn)音樂播放器

    這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)音樂播放器,擁有播放、暫停、重新播放和停止等功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-04-04
  • Android之RecyclerView實(shí)現(xiàn)時(shí)光軸效果示例

    Android之RecyclerView實(shí)現(xiàn)時(shí)光軸效果示例

    本篇文章主要介紹了Android之RecyclerView實(shí)現(xiàn)時(shí)光軸效果,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-02-02
  • Android Jetpack組件之ViewModel使用詳解

    Android Jetpack組件之ViewModel使用詳解

    Android中的ViewModel是一個(gè)可以用來存儲(chǔ)UI相關(guān)的數(shù)據(jù)的類。ViewModel的生命周期會(huì)比創(chuàng)建它的Activity、Fragment的生命周期長(zhǎng),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧
    2023-04-04
  • android TextView屬性的詳細(xì)介紹 分享

    android TextView屬性的詳細(xì)介紹 分享

    android TextView屬性的詳細(xì)介紹 分享,需要的朋友可以參考一下
    2013-05-05

最新評(píng)論

汝城县| 巴中市| 华蓥市| 南召县| 石楼县| 二连浩特市| 桦川县| 武强县| 临泽县| 翁源县| 阿拉善右旗| 乌拉特中旗| 大兴区| 贵州省| 城口县| 盖州市| 璧山县| 翁牛特旗| 阿克苏市| 晴隆县| 通城县| 玛纳斯县| 余姚市| 晋州市| 醴陵市| 连山| 崇义县| 清苑县| 镇雄县| 安图县| 平阴县| 同德县| 桃源县| 汉寿县| 安乡县| 潼南县| 揭阳市| 福泉市| 镇远县| 临桂县| 东兴市|