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

Android實(shí)現(xiàn)簡(jiǎn)易秒表功能

 更新時(shí)間:2022年09月11日 09:07:43   作者:遠(yuǎn)經(jīng)潮  
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)簡(jiǎn)易秒表功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android實(shí)現(xiàn)秒表功能的具體代碼,供大家參考,具體內(nèi)容如下

今天為了給師弟們講安卓,花了10分鐘寫(xiě)了一個(gè)簡(jiǎn)易的秒表app,現(xiàn)貼出代碼,供各位剛?cè)腴T(mén)以及還未入門(mén)的同學(xué)們參考

第一步:布局activity_main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
? ? xmlns:tools="http://schemas.android.com/tools"
? ? android:layout_width="match_parent"
? ? android:layout_height="match_parent"
? ? android:paddingBottom="@dimen/activity_vertical_margin"
? ? android:paddingLeft="@dimen/activity_horizontal_margin"
? ? android:paddingRight="@dimen/activity_horizontal_margin"
? ? android:paddingTop="@dimen/activity_vertical_margin"
? ? tools:context=".MainActivity" >
?
? ? <RelativeLayout
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:layout_centerInParent="true" >
?
? ? ? ? <LinearLayout
? ? ? ? ? ? android:id="@+id/top"
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:layout_centerHorizontal="true"
? ? ? ? ? ? android:orientation="horizontal" >
?
? ? ? ? ? ? <TextView
? ? ? ? ? ? ? ? android:id="@+id/mint"
? ? ? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="00"
? ? ? ? ? ? ? ? android:textSize="30dp" />
?
? ? ? ? ? ? <TextView
? ? ? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text=":"
? ? ? ? ? ? ? ? android:textSize="30dp" />
?
? ? ? ? ? ? <TextView
? ? ? ? ? ? ? ? android:id="@+id/sec"
? ? ? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="00"
? ? ? ? ? ? ? ? android:textSize="30dp" />
? ? ? ? </LinearLayout>
?
? ? ? ? <LinearLayout
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:layout_below="@+id/top"
? ? ? ? ? ? android:layout_centerHorizontal="true"
? ? ? ? ? ? android:orientation="horizontal" >
?
? ? ? ? ? ? <Button
? ? ? ? ? ? ? ? android:id="@+id/start"
? ? ? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="start" />
?
? ? ? ? ? ? <Button
? ? ? ? ? ? ? ? android:id="@+id/reset"
? ? ? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="reset" />
? ? ? ? </LinearLayout>
? ? </RelativeLayout>
?
</RelativeLayout>

第二步:實(shí)現(xiàn)秒表功能

package com.example.second;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
? ? private TextView mint;
? ? private TextView sec;
? ? private Button start;
? ? private Button reset;
? ? private long timeusedinsec;
? ? private boolean isstop = false;
? ? private Handler mHandler = new Handler() {
? ? ? ? /*
? ? ? ? ?* edit by yuanjingchao 2014-08-04 19:10
? ? ? ? ?*/
? ? ? ? @Override
? ? ? ? public void handleMessage(Message msg) {
? ? ? ? ? ? // TODO Auto-generated method stub
? ? ? ? ? ? super.handleMessage(msg);
? ? ? ? ? ? switch (msg.what) {
? ? ? ? ? ? case 1:
? ? ? ? ? ? ? ? // 添加更新ui的代碼
? ? ? ? ? ? ? ? if (!isstop) {
? ? ? ? ? ? ? ? ? ? updateView();
? ? ? ? ? ? ? ? ? ? mHandler.sendEmptyMessageDelayed(1, 1000);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? case 0:
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? }
?
? ? };
?
? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_main);
? ? ? ? initViews();
? ? }
? ? private void initViews() {
? ? ? ? mint = (TextView) findViewById(R.id.mint);
? ? ? ? sec = (TextView) findViewById(R.id.sec);
? ? ? ? reset = (Button) findViewById(R.id.reset);
? ? ? ? start = (Button) findViewById(R.id.start);
? ? ? ? reset.setOnClickListener(new OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View arg0) {
? ? ? ? ? ? ? ? // TODO Auto-generated method stub
? ? ? ? ? ??
? ? ? ? ? ? ? ? mint.setText("00");
? ? ? ? ? ? ? ? sec.setText("00");
? ? ? ? ? ? ? ? start.setText("start");
? ? ? ? ? ? ? ? timeusedinsec=0;
? ? ? ? ? ? ? ? isstop=true;
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? start.setOnClickListener(new OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View arg0) {
? ? ? ? ? ? ? ? // TODO Auto-generated method stub
? ? ? ? ? ? ? ? mHandler.removeMessages(1);
? ? ? ? ? ? ? ? String aaa=start.getText().toString();
? ? ? ? ? ? ? ? if(aaa.equals("start")){
? ? ? ? ? ? ? ? ? ? mHandler.sendEmptyMessage(1);
? ? ? ? ? ? ? ? ? ? isstop = false;
? ? ? ? ? ? ? ? ? ? start.setText("pause");
? ? ? ? ? ? ? ? }else {
? ? ? ? ? ? ? ? ? ? mHandler.sendEmptyMessage(0);
? ? ? ? ? ? ? ? ? ? isstop = true;
? ? ? ? ? ? ? ? ? ? start.setText("start");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ??
? ? ? ? ? ? }
? ? ? ? });
? ? }
? ? private void updateView() {
? ? ? ? timeusedinsec += 1;
? ? ? ? int minute = (int) (timeusedinsec / 60)%60;
? ? ? ? int second = (int) (timeusedinsec % 60);
? ? ? ? if (minute < 10)
? ? ? ? ? ? mint.setText("0" + minute);
? ? ? ? else
? ? ? ? ? ? mint.setText("" + minute);
? ? ? ? if (second < 10)
? ? ? ? ? ? sec.setText("0" + second);
? ? ? ? else
? ? ? ? ? ? sec.setText("" + second);
? ? }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android 自定義view仿支付寶咻一咻功能

    Android 自定義view仿支付寶咻一咻功能

    支付寶上有一個(gè)咻一咻的功能,就是點(diǎn)擊圖片后四周有水波紋的這種效果,今天就通過(guò)本文給大家分享實(shí)現(xiàn)此功能的思路及實(shí)例代碼,一起看看吧
    2016-12-12
  • Android中使用Intent在Activity之間傳遞對(duì)象(使用Serializable或者Parcelable)的方法

    Android中使用Intent在Activity之間傳遞對(duì)象(使用Serializable或者Parcelable)的

    這篇文章主要介紹了 Android中使用Intent在Activity之間傳遞對(duì)象(使用Serializable或者Parcelable)的方法的相關(guān)資料,需要的朋友可以參考下
    2016-01-01
  • Android CameraX打開(kāi)攝像頭預(yù)覽教程

    Android CameraX打開(kāi)攝像頭預(yù)覽教程

    大家好,本篇文章主要講的是Android CameraX打開(kāi)攝像頭預(yù)覽教程,感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話記得收藏一下
    2021-12-12
  • Android深入探究自定義View之嵌套滑動(dòng)的實(shí)現(xiàn)

    Android深入探究自定義View之嵌套滑動(dòng)的實(shí)現(xiàn)

    什么是嵌套滑動(dòng)?當(dāng)我們向下滑動(dòng)時(shí),首先是外部的布局向下滑動(dòng),然后才是內(nèi)部的RecyclerView滑動(dòng),向上滑動(dòng)也是如此。這就是嵌套滑動(dòng)的效果
    2021-11-11
  • Android側(cè)滑菜單之DrawerLayout用法詳解

    Android側(cè)滑菜單之DrawerLayout用法詳解

    今天小編就為大家分享一篇關(guān)于Android側(cè)滑菜單之DrawerLayout用法詳解,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧
    2019-03-03
  • Android四大組件之Activity詳細(xì)介紹

    Android四大組件之Activity詳細(xì)介紹

    大家好,本篇文章主要講的是Android四大組件之Activity詳解,感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話記得收藏一下,方便下次瀏覽
    2021-12-12
  • Android View 繪制機(jī)制的詳解

    Android View 繪制機(jī)制的詳解

    這篇文章主要介紹了Android View 繪制機(jī)制的詳解的相關(guān)資料,需要的朋友可以參考下
    2017-07-07
  • Android手機(jī)衛(wèi)士之確認(rèn)密碼對(duì)話框

    Android手機(jī)衛(wèi)士之確認(rèn)密碼對(duì)話框

    這篇文章主要為大家詳細(xì)介紹了Android手機(jī)衛(wèi)士之確認(rèn)密碼對(duì)話框,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-10-10
  • java實(shí)現(xiàn)靜默安裝apk

    java實(shí)現(xiàn)靜默安裝apk

    本文給大家分享的是如何實(shí)現(xiàn)偷偷的把一個(gè)安卓apk應(yīng)用安裝到手機(jī)上,而且不顯示確認(rèn)框,主要是通過(guò)反射來(lái)實(shí)現(xiàn),好了,小伙伴們仔細(xì)看下代碼吧,有需要的小伙伴可以參考下。
    2015-04-04
  • 一文深入探討Android Activity啟動(dòng)模式

    一文深入探討Android Activity啟動(dòng)模式

    在 Android 應(yīng)用開(kāi)發(fā)中,Activity 是用戶界面的核心組件,而 Activity 的啟動(dòng)模式則是決定應(yīng)用界面如何在任務(wù)棧中交互、管理以及呈現(xiàn)的關(guān)鍵因素,本文將深入探討 Android 中的 Activity 啟動(dòng)模式,詳細(xì)解釋每種模式的用途、適用場(chǎng)景
    2023-08-08

最新評(píng)論

新乡县| 五大连池市| 互助| 资源县| 上虞市| 普兰县| 芒康县| 武安市| 新营市| 五寨县| 谷城县| 日土县| 松滋市| 措美县| 灵川县| 临泉县| 铜鼓县| 隆尧县| 牡丹江市| 英德市| 镇雄县| 丘北县| 来凤县| 芦山县| 杭州市| 上虞市| 玉环县| 丰镇市| 尼木县| 溧水县| 固安县| 乐亭县| 偃师市| 金塔县| 双桥区| 沙坪坝区| 苏尼特左旗| 丰顺县| 崇明县| 江陵县| 仪陇县|