iis服务器助手广告广告
返回顶部
首页 > 资讯 > 移动开发 >Android多功能时钟开发案例(基础篇)
  • 601
分享到

Android多功能时钟开发案例(基础篇)

Android 2022-06-06 08:06:45 601人浏览 安东尼
摘要

本文我们进入Android多功能时钟开发实战学习,具体的效果可以参考手机上的时钟,内容如下 首先我们来看一看布局文件layout_main.xml 整个布局: <Fr

本文我们进入Android多功能时钟开发实战学习,具体的效果可以参考手机上的时钟,内容如下

首先我们来看一看布局文件layout_main.xml

整个布局:


<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> 

 整个布局整的是一个FrameLayout,我们在里面放了一个TabHost,接下来我们就可以在里面直接添加自己想要的布局了,可能初学者初一看会有那么一个疑问,就是<com.example.clock.……></com.example.clock.……>这个是什么东西??这是一个自定义的控件,我们创建的一个继承了LinearLayout的一个类(讲解可以参考这里//www.jb51.net/article/85515.htm),上面我们看到了四个这样的标签,表示我们有四个这样的Tab页面。关于布局的东西这里就不多讲了,之后会把我自己在学习过程中的一些不懂,以及相关的知识点上传到资源中,大家可以下载来看看。

完整的布局文件代码:


<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添加标签 
 // 新建一个newTabSpec(newTabSpec)用来指定该标签的id(就是用来区分标签)的 
 // 设置其标签和图表(setIndicator) 
 // 设置内容(setContent) 
  
 tabHost.addTab(tabHost.newTabSpec("tabTime").setIndicator("时钟") 
  .setContent(R.id.tabTime)); 
 tabHost.addTab(tabHost.newTabSpec("tabAlarm").setIndicator("闹钟") 
  .setContent(R.id.tabAlarm)); 
 tabHost.addTab(tabHost.newTabSpec("tabTimer").setIndicator("计时器") 
  .setContent(R.id.tabTimer)); 
 tabHost.addTab(tabHost.newTabSpec("tabStopWatch").setIndicator("秒表") 
  .setContent(R.id.tabStopWatch)); 
} 

在MainActivity中主要的操作就是设置TabHost,上面的代码中已经贴上了解释,这里就不讲了,接下来一篇我们就重点来讲讲时钟、闹钟、计时器和秒表这四部分,希望大家继续学习。

您可能感兴趣的文章:Android获取设备CPU核数、时钟频率以及内存大小的方法android实现widget时钟示例分享Android多功能时钟开发案例(实战篇)Android 仿日历翻页、仿htc时钟翻页、数字翻页切换效果android高仿小米时钟(使用Camera和Matrix实现3D效果)Android实现简单时钟View的方法Android仿小米时钟效果Android画个时钟玩玩Android编程基于自定义控件实现时钟功能的方法Android canvas自定义实现时钟效果


--结束END--

本文标题: Android多功能时钟开发案例(基础篇)

本文链接: https://www.lsjlt.com/news/24986.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Android多媒体功能开发(2)——FileProvider
    使用系统多媒体界面需要在我们的应用和其他应用之间通过Intent传递音频、图片、视频文件的信息。随着Android版本的升级,对应用数据安全性方面的限制越来越多。 Android 6以后不允许应用在外部存储随便创建目录,只能在Android...
    99+
    2023-08-31
    android 音视频
  • Android开发基础使用ProgressBar加载进度条示例
    目录前言使用方法总结前言 之前我们用过WebView类,打开网页时就会出现加载网页的情况,为了让我们直观的感受到网页加载到什么程度而不是白白干等着空白页,于是加载进度条就是一个很好...
    99+
    2023-02-05
    Android ProgressBar加载进度条 Android ProgressBar
  • KTV小程序开发的基础功能有哪些
    这篇文章主要介绍了KTV小程序开发的基础功能有哪些,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。一、KTV小程序开发有哪些功能?KTV是城市里年轻人经常花钱的地方,也是年轻人...
    99+
    2023-06-27
  • 智能停车小程序开发的基础功能有哪些
    小编给大家分享一下智能停车小程序开发的基础功能有哪些,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!如今,城市中私家车的数量在增加,城市也面临着交通拥堵和停车困难的...
    99+
    2023-06-27
  • 菜谱小程序开发的基础功能有哪些
    这篇文章主要介绍菜谱小程序开发的基础功能有哪些,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!随着生活水平的提高,人们对生活质量有了更高的要求,尤其是对食物和饮料。与以前的食客相比,现在的食客可以说是非常挑剔,不仅对口...
    99+
    2023-06-27
  • 收租小程序开发的基础功能有哪些
    这篇文章将为大家详细讲解有关收租小程序开发的基础功能有哪些,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。首先,房东使用房客注册管理,根据社区,房屋号牌,姓名,电话号码,租金和租赁期限对所有房客进行注册。 ...
    99+
    2023-06-27
  • 绘图小程序开发的基础功能有哪些
    这篇文章主要为大家展示了“绘图小程序开发的基础功能有哪些”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“绘图小程序开发的基础功能有哪些”这篇文章吧。 为什么像画图小程序这样的软件在小程序中备受青睐...
    99+
    2023-06-27
  • 名片小程序开发的基础功能有哪些
    这篇文章将为大家详细讲解有关名片小程序开发的基础功能有哪些,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。一、开发名片小程序有什么市场优势? 现在人们见面交流,经常直接交流微信和朋友,纸质名片还是其中一种。...
    99+
    2023-06-27
  • 唱歌小程序开发的基础功能有哪些
    这篇文章给大家分享的是有关唱歌小程序开发的基础功能有哪些的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。一、唱歌小程序开发市场需求分析  随着经济和文化发展的不断改善,生活节奏不断加快。人们需要适合他们的...
    99+
    2023-06-27
  • 养生小程序开发的基础功能有哪些
    这篇文章主要为大家展示了“养生小程序开发的基础功能有哪些”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“养生小程序开发的基础功能有哪些”这篇文章吧。养生小程序开发前景养生越来越年轻化,侧面也反映出...
    99+
    2023-06-27
  • 画画小程序开发的基础功能有哪些
    小编给大家分享一下画画小程序开发的基础功能有哪些,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!学画画需要的是从兴趣到掌握相关技巧,而不是从兴趣走向无趣。其实很多人对于画画都有相当的天赋,由于家庭的缘故这种天赋也渐渐的在岁月...
    99+
    2023-06-27
  • 生鲜小程序开发的基础功能是什么
    这篇文章主要为大家展示了“生鲜小程序开发的基础功能是什么”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“生鲜小程序开发的基础功能是什么”这篇文章吧。生鲜小程序开发:随着移动互联网的快速发展,许多传...
    99+
    2023-06-27
  • 母婴小程序开发的基础功能有哪些
    这篇文章主要介绍了母婴小程序开发的基础功能有哪些,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。随着婴幼儿市场主要消费者的逐渐变化,母婴行业进入了一个新的时代,传统的实体店和纯...
    99+
    2023-06-27
  • Android编程实现定时发短信功能示例
    本文实例讲述了Android编程实现定时发短信功能。分享给大家供大家参考,具体如下:第一,要实现发短信的功能,必须要用到android系统中发短信的权限,即在AndoridManifest.xml中添加如下内容<uses-permis...
    99+
    2023-05-30
    android 短信 roi
  • Android多功能视频播放器GSYVideoPlayer开发流程
    目录前言引入依赖开发设置具体实现前言 今天,和大家分享一个开源的多功能视频播放器 — GSYVideoPlayer,支持弹幕,滤镜、水印、gif截图,片头广告,声音、亮度...
    99+
    2022-11-13
    Android GSYVideoPlayer Android视频播放器
  • Android开发基础实现最简单的视频播放示例
    目录正篇使用方法最终效果展示总结正篇 视频播放是很平常的一件事情,但如何在APP中实现呢,其实蛮简单的,方法也很多,但作为基础的就是使用VideoView了,下面我们来看看如何使...
    99+
    2023-02-05
    Android开发简单视频播放 Android 视频播放
  • 蛋糕店小程序开发的基础功能有哪些
    这篇文章主要介绍了蛋糕店小程序开发的基础功能有哪些,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。蛋糕店小程序开发的基本功能 商品分类展示:蛋糕店小程序对不同的蛋糕甜品进行分类...
    99+
    2023-06-27
  • 出境游小程序开发的基础功能有哪些
    这篇文章主要为大家展示了“出境游小程序开发的基础功能有哪些”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“出境游小程序开发的基础功能有哪些”这篇文章吧。出境游小程序开发:近年来,随着旅游业的全面改...
    99+
    2023-06-27
  • PHP开发实战:打造高效多篇文章点赞功能
    对不起,我不能提供具体的编程代码示例。如果您需要关于PHP开发实战的指导或者建议,我很乐意为您提供。请告诉我您需要哪方面的帮助,我会尽量提供相关信息。以上就是PHP开发实战:打造高效多...
    99+
    2024-02-27
    php 点赞 多篇文章
  • Android蓝牙的开启和搜索设备功能开发实例
    目录概览设置蓝牙蓝牙权限设置蓝牙查找设备查询已配对设备发现设备启用可检测性概览 Android 平台包含蓝牙网络堆栈支持,此支持能让设备以无线方式与其他蓝牙设备交换数据。应用框架提供...
    99+
    2023-05-14
    Android蓝牙的开启和搜索 Android蓝牙的开启 Android蓝牙的搜索
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作