该闹钟是根据我们手机闹钟设计的一个简单的闹钟APP,其中包含时钟、闹钟、秒表和计时器功能。用户可以对闹钟添加和删除,可以对秒表计时、暂停和重置,对计时器可以暂停、计时、继续和重置等功能。
下图为闹钟的时钟功能界面和闹钟功能界面
下图为闹钟的计时功能和秒表功能
基本的界面就是这样了,接下来我们就开始详细的介绍闹钟的设计过程。
闹钟的布局文件代码如下
由于该闹钟系统包含时钟、闹钟、计时器、秒表四个功能,所以只要插入TabHost控件就能实现在手机上更加简洁地展示四个功能。后面只需要在TabHost中插入四个Tab用来切换展示的界面,具体的代码实现如下:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tabHost = (TabHost)findViewById(android.R.id.tabhost);
tabHost.setup();
TabWidget tabWidget = tabHost.getTabWidget();
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));
for (int i =0; i < tabWidget.getChildCount(); i++) {
//修改Tabhost高度和宽度
tabWidget.getChildAt(i).getLayoutParams().height = 90;
tabWidget.getChildAt(i).getLayoutParams().width = 65;
//修改显示字体大小
TextView tv = (TextView) tabWidget.getChildAt(i).findViewById(android.R.id.title);
tv.setTextSize(25);
tv.setTextColor(this.getResources().getColorStateList(android.R.color.black));
}
stopWatchView = (StopWatchView)findViewById(R.id.tabStopWatch);
}
1、 因为时钟功能中,只要显示当前的日期和时钟就可以了,所以只需要插入一个TextView用来显示日期时间就可以了。
<com.example.administrator.alarm5.TimeView
android:id="@+id/tabTime"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:textAlignment="center"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/tvTime"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="36sp"
android:textAlignment="center"
android:textStyle="normal|bold" />
</com.example.administrator.alarm5.TimeView>
2.1、闹钟功能就相对时钟功能就复杂很多了,因为这里需要对闹钟进行增加,删除等操作,而且可能需要展示多个闹钟的时间。所以这里需要用到有一个Button控件用来增加闹钟和一个ListView控件用来展示闹钟的时间。
<com.example.administrator.alarm5.AlarmView
android:id="@+id/tabAlarm"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<ListView
android:id="@+id/lvAlarmList"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="0dp"
android:headerDividersEnabled="true"
android:footerDividersEnabled="true">
</ListView>
<Button
android:id="@+id/btnAddAlarm"
android:text="添加闹钟"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textSize="18sp" />
</com.example.administrator.alarm5.AlarmView>
2.2、当闹钟想起来的时候,也需要展现一个界面提醒用户,所以我们还需要设计另外一个.xml布局文件。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<TextView
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/font_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="闹铃响起来了!" />
<Button
android:id="@+id/close_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="关闭闹钟"
android:layout_alignParentBottom="true"
android:layout_marginBottom="100dp"
/>
</RelativeLayout>
效果图如下
3、秒表功能包含四个功能键,分别为开始,暂停、继续和重置。所以需要四个Button,然后需要三个EditText分别用来给用户输入时分秒。具体的代码如下:
<com.example.administrator.alarm5.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:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/etHour"
android:inputType="number"
android:singleLine="true"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textStyle="normal|bold" />
<TextView
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=":"
android:textAlignment="center"
android:textStyle="normal|bold" />
<EditText
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/etMin"
android:inputType="number"
android:singleLine="true"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textStyle="normal|bold" />
<TextView
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=":"
android:textAlignment="center"
android:textStyle="normal|bold" />
<EditText
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/etSec"
android:inputType="number"
android:singleLine="true"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textStyle="normal|bold" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/btnGroup"
android:orientation="horizontal">
<Button
android:id="@+id/btnStart"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="开始"
android:textAlignment="center"
android:textSize="18sp" />
<Button
android:id="@+id/btnPause"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="暂停"
android:textSize="18sp"
android:textAlignment="center" />
<Button
android:id="@+id/btnResume"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="继续"
android:textSize="18sp"
android:textAlignment="center" />
<Button
android:id="@+id/btnReset"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="重置"
android:textSize="18sp"
android:textAlignment="center" />
</LinearLayout>
</com.example.administrator.alarm5.TimerView>
4、剩下最后一个功能项就是计时器了,这个和上面讲了秒表比较类似,不同的是多一个Button按钮用来计时,另外还需要一个ListView用来显示计时的时间,详细的代码如下:
<com.example.administrator.alarm5.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"
android:textAlignment="center"
android:fontFamily="sans-serif"
android:textStyle="normal|bold" />
<TextView
android:text=":"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textAlignment="center"
android:textStyle="normal|bold" />
<TextView
android:id="@+id/timeMin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textAlignment="center"
android:textStyle="normal|bold" />
<TextView
android:text=":"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textAlignment="center"
android:textStyle="normal|bold" />
<TextView
android:id="@+id/timeSec"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textAlignment="center"
android:textStyle="normal|bold" />
<TextView
android:text=":"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textAlignment="center"
android:textStyle="normal|bold" />
<TextView
android:id="@+id/timeMSec"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textAlignment="center"
android:textStyle="normal|bold" />
</LinearLayout>
<ListView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="@+id/lvWatchTimeList"
android:background="@color/common_google_signin_btn_text_dark_default">
</ListView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="开始"
android:id="@+id/btnSWStart"
android:textAlignment="center"
android:textStyle="normal|bold"
android:textSize="18sp" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="暂停"
android:id="@+id/btnSWPause"
android:textAlignment="center"
android:textSize="18sp" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="继续"
android:id="@+id/btnSWResume"
android:textAlignment="center"
android:textSize="18sp" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="重置"
android:id="@+id/btnSWReset"
android:textSize="18sp"
android:textAlignment="center" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="计时"
android:id="@+id/btnSWLap"
android:textSize="18sp"
android:textAlignment="center" />
</LinearLayout>
</com.example.administrator.alarm5.StopWatchView>
上面基本上都介绍完界面布局的代码,这些代码都是activity_mian.xml中的部分代码,这里只是展示了所要说明的部分,下一节将会介绍这个闹钟的后端代码。
文章浏览阅读1.2k次。最简单的方法是用pgrep 获取进程号,然后kill掉_linux 杀掉进程脚本
文章浏览阅读1.8k次,点赞3次,收藏24次。实验三 单元测试实验类别:基本实验实验目的:(1)掌握单元测试技术,并要求按照单元测试的要求设计测试用例。(2)掌握在Eclipse里进行Junit4测试的技术。实验内容:日期问题测试以下程序:该程序有三个输入变量month、day、year(month、day和year均为整数值,并且满足:1≤month≤12、1≤day≤31和1900≤ year ≤2050),分别作为输入日期的月份、日、年份,通过程序可以输出该输入日期在日历上隔一天的日期。例如,输入为 2004 年11月30日,则该程_请完成隔一天日期的判定表构建
文章浏览阅读1.1k次。AHB是为提出高性能可综合设计的要求而产生的新一代AMBA总线。它是一种支持多总线主机和提供高带宽操作的高性能总线。AMBA AHB实现了高性能,高时钟频率系统的以下特征要求:这条高级总线和当今的APB能够有效的桥接确保了能够方便集成任何现有的设计。AMBA AHB的设计可能包含一个或者多个主机,一个典型的系统将至少包含处理器和测试接口。然而,将直接数据存取(DMA)或者数字信号处理器(DSP)包含作总线主机也很普通。外部储存器接口,APB桥和任何内部储存器是最常见的AHB从机。然而,低带宽的外设通常都是_ahb仲裁器设计
文章浏览阅读7.2k次,点赞7次,收藏23次。好久没写博客了,最近一直在写新项目。这两天基本上把该完成的都完成的差不多了。 正好新项目用到了很多以前没有用过的技术,在此总结一下。本文我们先来说一下一下组件化。组件化很早就有了,网上也有很多例子。讲的都非常好,我这里也只是把自己在实际使用的情况做一下记录。新项目中用到了组件化开发的思想。为什么要用到组件化呢? 因为本来公司项目是多个角色多种任务都在一个App中的。结果等我快完成的差不..._android模块化
文章浏览阅读5.5k次。原标题:五行中,你属什么就是什么样的人!太准了~ 世界是由金、木、水、火、土五种属性的物质所构成的,世间万物自有其五行属性。所以,世界上的万物或现象都是可以根据五行的属性来进行归类。今天就来为大家讲讲,五行与人之间的关系,看看你的五行属什么?01什么是五行?五行是我国古代先辈们用来说明世界万物的形成及其相互关系的一种理论,五行分别指金、木、水、火、土,它们之间相生相克,使大自然产生变化,同时影响..._命主属性是什么意思
文章浏览阅读2.8k次。MyBatis-Plus(简称 MP)是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发提高效率而生。该框架由baomidou(苞米豆)组织开发并且开源的。_mybatisplus oracle
文章浏览阅读2k次。计算机二级科目怎么选哪个最简单计算机二级科目怎幺选择呢,哪个比较简单的,下面小编为大家提高计算机二级科目都有什幺怎样选择,仅供大家参考。计算机二级主要分为几类计算机二级考试主要分两类:一类是语言程序设计,(如:C、C++、Python、Java、Visual Basic、WEB);另一类是数据库程序设计(如:Access、MySQL)MS Office难度:★★★价值:★★★★计算机的基础知识,W..._msoffice和python哪个简单
文章浏览阅读1.2k次。 在安装好Tensorflow models(参见我的AI之路(18)--Tensorflow的模型安装之object_detection)后,下载Object_Detection_Tensorflow_API.ipynb文件,这个文件相对于object_detection里自带的object_detection_tutorial.ipynb来说,除了对静态测试图片中的狗和人等物体的识别,后面增..._imageio: 'ffmpeg-win32-v3.2.4.exe' was not found on your computer; downloadi
文章浏览阅读328次。作者:Java我人生blog.csdn.net/chenleixing/article/details/44994571没事不用存储过程,既然用了,就看看怎么优化吧最近在忙着优化集团公司..._if @lotname<>
文章浏览阅读1.6w次,点赞6次,收藏84次。原帖地址:http://www.anandtech.com/show/9969/jedec-publishes-hbm2-specification高带宽存储器(HBM)技术解决了与现代DRAM相关的两个关键问题:它显着增加了计算设备(例如GPU)可用的带宽并降低了功耗。第一代HBM在容量和时钟速率方面有许多限制。但是,第二代HBM有望消除它们。制定DRAM标准的主要半导体工程贸易组织JEDEC最近发布了第二代HBM(HBM2)的最终规范,这意味着该组织的成员已经批准了该标准。新的存储技术建立在原始JE_kgsd
文章浏览阅读247次。类似问题答案中山大学计算机类专业2016年在天津理科高考录取最低分数线学校 地 区 专业 年份 批次 类型 分数 中山大学 天津 计算机类 2016 一批 理科 629 学校 地 区 专业 年份 批次 类型 分数 中山大学 天津 计算机类 2016 一批 理科 629 中山大学 天津 计算机类 2015 一批 理科 643 中山大学 天津 计算机类 2015 一批 理科 643中山大学计算机类专业..._zhongshandaxue jisuanjileifenliu
文章浏览阅读326次。的优化工具箱提供了各种优化函数,这些优化 函数可以通过在命令行输入相应的函数名加以调用;此外 为了使用方便,MATLAB 还提供了图形界面的优化工具 (GUI Optimization ......MATLAB优化工具箱 5.1 工具箱概述 5.1.1 工具箱的功能 5.1.2 工具箱的新特色 5.1.3 工具箱的结构 5.2 工具箱函数 5.3 GUI优化工具 5.3.1 GUI......矩阵..._matlab中2022b的gui优化