{"id":920,"date":"2017-03-14T12:45:59","date_gmt":"2017-03-14T04:45:59","guid":{"rendered":"http:\/\/www.yusian.com\/blog\/?p=920"},"modified":"2020-12-01T12:47:20","modified_gmt":"2020-12-01T04:47:20","slug":"android%e5%bc%80%e5%8f%91%e5%ae%9e%e6%88%98%e5%b0%8f%e6%b8%b8%e6%88%8f1%e7%a7%92onesecond%ef%bc%8c%e9%80%82%e5%90%88%e6%96%b0%e6%89%8b%e8%ae%ad%e7%bb%83","status":"publish","type":"post","link":"https:\/\/www.yusian.com\/blog\/android\/2017\/03\/14\/124559920.html","title":{"rendered":"Android\u5f00\u53d1\u5b9e\u6218\u5c0f\u6e38\u620f\u201c1\u79d2OneSecond\u201d\uff0c\u9002\u5408\u65b0\u624b\u8bad\u7ec3"},"content":{"rendered":"<p>1\u3001\u5148\u4e0a\u56fe\u770b\u4e0b\u6548\u679c<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.yusian.com\/blog\/wp-content\/uploads\/2017\/03\/20170314100957.jpg\" alt=\"\" width=\"150\" height=\"267\" class=\"alignnone size-full wp-image-929\" \/><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.yusian.com\/blog\/wp-content\/uploads\/2017\/03\/20170314101039.jpg\" alt=\"\" width=\"150\" height=\"267\" class=\"alignnone size-medium wp-image-930\" \/><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.yusian.com\/blog\/wp-content\/uploads\/2017\/03\/20170314101113.jpg\" alt=\"\" width=\"150\" height=\"267\" class=\"alignnone size-medium wp-image-931\" \/><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.yusian.com\/blog\/wp-content\/uploads\/2017\/03\/20170314101159.jpg\" alt=\"\" width=\"150\" height=\"267\" class=\"alignnone size-medium wp-image-932\" \/><\/p>\n<p>2\u3001\u57fa\u672c\u9700\u6c42<br \/>\n2.1\u3001\u73a9\u5bb6\u51ed\u4e2a\u4eba\u611f\u89c9\u957f\u6309\u70b9\u51fb\u533a\u57df\uff0c\u5927\u69821\u79d2\u65f6\u677e\u5f00\uff0c\u7cfb\u7edf\u4f1a\u68c0\u6d4b\u672c\u6b21\u65f6\u95f4\uff1b<br \/>\n2.2\u3001\u5982\u679c\u65f6\u95f4\u8bef\u5dee\u57280.1\u79d2\u5185(\u8d85\u8fc70.1\u79d2\u6216\u5dee0.1\u79d2)\u5747\u8bb0\u5f55\u201c\u5927\u795e\u201d1\u6b21\uff0c\u5426\u5219\u8bb0\u5f55\u201c\u51e1\u4eba\u201d1\u6b21\uff1b<br \/>\n2.3\u3001\u201c\u5927\u795e\u201d1\u6b21\u4ee5\u7ea2\u8272\u663e\u793a\uff0c\u7a81\u51fa\u6548\u679c\uff1b<\/p>\n<p>3\u3001\u4e3b\u8981\u6280\u672f\u70b9<br \/>\n3.1\u3001\u76f8\u5bf9\u5e03\u5c40\u52a0\u7ebf\u6027\u5e03\u5c40\uff0c\u6574\u4f53\u4f7f\u7528\u76f8\u5bf9\u5e03\u5c40\uff0c\u4e2d\u95f4\u6309\u94ae\u90e8\u5206\u4f7f\u7528\u7ebf\u6027\u5e03\u5c40\uff1b<br \/>\n3.2\u3001\u4e2d\u95f4\u957f\u6309\u533a\u57df\u4e0d\u662f\u6309\u94ae\uff0c\u662f\u4e00\u4e2a\u5e03\u5c40(\u53ef\u4ee5\u770b\u6210\u662f\u4e00\u4e2aView)\uff0c\u5e76\u4e14\u7ed1\u5b9aonTouch\u4e8b\u4ef6\uff1b<br \/>\n3.3\u3001\u666e\u901aView\u8981\u5b9e\u73b0Touch\u4e8b\u4ef6\u5fc5\u987b\u52a0\u4e0a\u5c5e\u6027android:clickable=&#8221;true&#8221;\uff0c\u5426\u5219\u53ea\u80fdTouchDown\uff0c\u5176\u4ed6\u5747\u65e0\u6cd5\u54cd\u5e94\uff1b<br \/>\n3.4\u3001\u201c\u6309\u94ae\u201d\u4e0a\u6709\u4e24\u884c\u6587\u5b57\uff0c\u5fc5\u8981\u7684\u65f6\u5019\u53ea\u663e\u793a\u4e00\u884c\uff0c2\u884c\u65f6\u5e73\u5206\uff0c1\u884c\u662f\u5c45\u4e2d\uff1b<br \/>\n3.5\u3001android:visibility=&#8221;xxx&#8221;\uff0cxxx\u6709\u4e09\u4e2a\u679a\u4e3e\u503c\u5206\u522b\u4e3a\uff1agone\u3001visible\u3001invisible\uff1b<!--more--><\/p>\n<p>4\u3001\u5173\u952e\u4ee3\u7801<br \/>\nXML<\/p>\n<pre line=\"1\" lang=\"java\"><?xml version=\"1.0\" encoding=\"utf-8\"?>\n<RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:background=\"#0096FA\"\n    tools:context=\"com.yusian.onesecond.MainActivity\">\n\n    <TextView\n        android:id=\"@+id\/tv_tag\"\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:textSize=\"40sp\"\n        android:text=\"\u4f60\u7684\u4e00\u79d2\u949f\\n\u6709\u591a\u957f\uff1f\"\n        android:gravity=\"center\"\n        android:layout_centerHorizontal=\"true\"\n        android:layout_marginTop=\"30dp\"\n        android:textColor=\"@color\/sa_yellow\"\/>\n    <TextView\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:text=\"How long is your one second\"\n        android:layout_below=\"@id\/tv_tag\"\n        android:layout_centerInParent=\"true\"\n        android:layout_marginTop=\"20dp\"\n        android:textSize=\"20sp\"\n        android:textColor=\"#FFFFFF\"\/>\n\n    <LinearLayout\n        android:id=\"@+id\/ll_btn\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"60dp\"\n        android:background=\"#CCCCCC\"\n        android:layout_centerInParent=\"true\"\n        android:layout_margin=\"10dp\"\n        android:gravity=\"center\"\n        android:clickable=\"true\"\n        android:orientation=\"vertical\">\n\n        <TextView\n            android:id=\"@+id\/ll_btn_time\"\n            android:layout_width=\"wrap_content\"\n            android:layout_height=\"wrap_content\"\n            android:text=\"\u6309\u4f4f\u5f00\u59cb\"\n            android:textSize=\"18sp\"\/>\n        <TextView\n            android:id=\"@+id\/ll_btn_tag\"\n            android:layout_width=\"wrap_content\"\n            android:layout_height=\"wrap_content\"\n            android:text=\"\u7889\u5821\u4e86,\u5c11\u4fa0\u4f60\u662f\u5927\u795e\"\n            android:visibility=\"visible\"\n            android:textColor=\"#FFFFFF\"\n            android:textSize=\"15sp\"\/>\n\n    <\/LinearLayout>\n\n    <TextView\n        android:id=\"@+id\/tv_normal\"\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:text=\"\u51e1\u4eba\uff1a0\"\n        android:textSize=\"18sp\"\n        android:layout_centerHorizontal=\"true\"\n        android:layout_below=\"@id\/ll_btn\"\n        android:textColor=\"@color\/sa_yellow\"\n        android:layout_marginTop=\"20dp\"\/>\n\n    <TextView\n        android:id=\"@+id\/tv_god\"\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:layout_below=\"@id\/tv_normal\"\n        android:layout_centerHorizontal=\"true\"\n        android:layout_margin=\"10dp\"\n        android:textSize=\"18sp\"\n        android:text=\"\u5927\u795e\uff1a0\"\n        android:textColor=\"@color\/sa_yellow\"\/>\n<\/RelativeLayout><\/pre>\n<p>Activity<\/p>\n<pre line=\"1\" lang=\"java\">package com.yusian.onesecond;\n\nimport android.graphics.Color;\nimport android.support.v7.app.AppCompatActivity;\nimport android.os.Bundle;\nimport android.view.MotionEvent;\nimport android.view.View;\nimport android.widget.LinearLayout;\nimport android.widget.TextView;\nimport java.text.DecimalFormat;\n\nimport static java.lang.Math.abs;\n\npublic class MainActivity extends AppCompatActivity {\n    private LinearLayout ll_btn;\n    long touchDownTime, touchUpTime;\n    int godCount, normalCount;\n    TextView tv_god, tv_normal, ll_btn_time, ll_btn_tag;\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_main);\n        findView();\n    }\n\n    \/*\u521d\u59cb\u5316\u57fa\u7840\u63a7\u4ef6\u53ca\u5f15\u7528*\/\n    private void findView() {\n        tv_god = (TextView)findViewById(R.id.tv_god);\n        tv_normal = (TextView)findViewById(R.id.tv_normal);\n\n        ll_btn_time = (TextView)findViewById(R.id.ll_btn_time);\n        ll_btn_tag = (TextView)findViewById(R.id.ll_btn_tag);\n        ll_btn = (LinearLayout) findViewById(R.id.ll_btn);\n\n        ll_btn.setOnTouchListener(new View.OnTouchListener() {\n            @Override\n            public boolean onTouch(View v, MotionEvent event) {\n                System.out.println(String.valueOf(event.getAction()));\n                int even = event.getAction();\n                \/\/ \u6309\u4e0b\u53bb\u7684\u65f6\u5019\n                if (even == MotionEvent.ACTION_DOWN){\n                    touchDownTime = System.currentTimeMillis();\n                    v.setBackgroundColor(Color.YELLOW);\n\n                    ll_btn_time.setText(\"\u6b63\u5728\u6309\u4e0b\");\n                    ll_btn_time.setTextColor(Color.BLACK);\n                    ll_btn_tag.setVisibility(View.GONE);\n                }\n                \/\/ \u62ac\u8d77\u6765\u7684\u65f6\u5019\n                if (even == MotionEvent.ACTION_UP){\n                    touchUpTime = System.currentTimeMillis();\n                    calculate();\n                }\n                return false;\n            }\n        });\n    }\n\n    \/*\u5224\u65ad\u65f6\u95f4\u8ba1\u7b97*\/\n    private void calculate(){\n        long pressTime = touchUpTime - touchDownTime;\n        if (pressTime == 0) return;\n\n        DecimalFormat decimal = new DecimalFormat(\"0.000\");\n        ll_btn_time.setText(decimal.format(pressTime * 0.001) + \"\u79d2\");\n\n        if (abs(pressTime - 1000) > 100){\n            normalCount ++;\n            ll_btn.setBackgroundColor(Color.rgb(204, 204, 204));\n\n            ll_btn_time.setTextColor(Color.BLACK);\n            ll_btn_tag.setVisibility(View.GONE);\n            tv_normal.setText(\"\u51e1\u4eba\uff1a\" + normalCount);\n        }else{\n            godCount ++;\n            ll_btn.setBackgroundColor(Color.rgb(200, 0, 0));\n\n            ll_btn_time.setTextColor(Color.WHITE);\n            ll_btn_tag.setVisibility(View.VISIBLE);\n            tv_god.setText(\"\u5927\u795e\uff1a\" + godCount);\n        }\n    }\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001\u5148\u4e0a\u56fe\u770b\u4e0b\u6548\u679c 2\u3001\u57fa\u672c\u9700\u6c42 2.1\u3001\u73a9\u5bb6\u51ed\u4e2a\u4eba\u611f\u89c9\u957f\u6309\u70b9\u51fb\u533a\u57df\uff0c\u5927\u69821\u79d2\u65f6\u677e\u5f00\uff0c\u7cfb\u7edf\u4f1a\u68c0\u6d4b\u672c\u6b21\u65f6\u95f4\uff1b 2.2\u3001\u5982\u679c\u65f6\u95f4\u8bef\u5dee\u57280.1\u79d2\u5185(\u8d85\u8fc70.1\u79d2\u6216\u5dee0.1\u79d2)\u5747\u8bb0\u5f55\u201c\u5927\u795e\u201d1\u6b21\uff0c\u5426\u5219\u8bb0\u5f55\u201c\u51e1\u4eba\u201d1\u6b21\uff1b 2.3\u3001\u201c\u5927\u795e\u201d1\u6b21\u4ee5\u7ea2\u8272\u663e\u793a\uff0c\u7a81\u51fa\u6548\u679c\uff1b 3\u3001\u4e3b\u8981\u6280\u672f\u70b9 3.1\u3001\u76f8\u5bf9\u5e03\u5c40\u52a0\u7ebf\u6027\u5e03\u5c40\uff0c\u6574\u4f53\u4f7f\u7528\u76f8\u5bf9\u5e03\u5c40\uff0c\u4e2d\u95f4\u6309\u94ae\u90e8\u5206\u4f7f\u7528\u7ebf\u6027\u5e03\u5c40\uff1b 3.2\u3001\u4e2d\u95f4\u957f\u6309\u533a\u57df\u4e0d\u662f\u6309\u94ae\uff0c\u662f\u4e00\u4e2a\u5e03\u5c40(\u53ef\u4ee5\u770b\u6210\u662f\u4e00\u4e2aView)\uff0c\u5e76\u4e14\u7ed1\u5b9aonTouch\u4e8b\u4ef6\uff1b 3.3\u3001\u666e\u901aView\u8981\u5b9e\u73b0Touch\u4e8b\u4ef6\u5fc5\u987b\u52a0\u4e0a\u5c5e\u6027android:clickable=&#8221;true&#8221;\uff0c\u5426\u5219\u53ea\u80fdTouchDown\uff0c\u5176\u4ed6\u5747\u65e0\u6cd5\u54cd\u5e94\uff1b 3.4\u3001\u201c\u6309\u94ae\u201d\u4e0a\u6709\u4e24\u884c\u6587\u5b57\uff0c\u5fc5\u8981\u7684\u65f6\u5019\u53ea\u663e\u793a\u4e00\u884c\uff0c2\u884c\u65f6\u5e73\u5206\uff0c1\u884c\u662f\u5c45\u4e2d\uff1b 3.5\u3001android:visibility=&#8221;xxx&#8221;\uff0cxxx\u6709\u4e09\u4e2a\u679a\u4e3e\u503c\u5206\u522b\u4e3a\uff1agone\u3001visible\u3001invisible\uff1b<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[33,20],"class_list":["post-920","post","type-post","status-publish","format-standard","hentry","category-android","tag-33","tag-basics"],"_links":{"self":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/920","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/comments?post=920"}],"version-history":[{"count":0,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/920\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/media?parent=920"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/categories?post=920"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/tags?post=920"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}