{"id":901,"date":"2017-03-08T10:27:16","date_gmt":"2017-03-08T02:27:16","guid":{"rendered":"http:\/\/www.yusian.com\/blog\/?p=901"},"modified":"2017-03-08T10:27:16","modified_gmt":"2017-03-08T02:27:16","slug":"android%e8%a7%a6%e5%b1%8f%e4%ba%8b%e4%bb%b6%e7%ae%80%e5%8d%95%e5%a4%84%e7%90%86%e4%b8%8e%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/www.yusian.com\/blog\/android\/2017\/03\/08\/102716901.html","title":{"rendered":"Android\u89e6\u5c4f\u4e8b\u4ef6\u7b80\u5355\u5904\u7406\u4e0e\u5b9e\u73b0"},"content":{"rendered":"<p>1\u3001\u4e0a\u56fe\uff0c\u65e0\u56fe\u65e0\u771f\u76f8<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.yusian.com\/blog\/wp-content\/uploads\/2017\/03\/20170308101910.jpg\" alt=\"\" width=\"360\" height=\"202\" class=\"alignnone size-full wp-image-902\" \/><\/p>\n<p>2\u3001Demo\u57fa\u672c\u8bbe\u8ba1\u539f\u7406<br \/>\n2.1\u3001\u76d1\u542c\u5c4f\u5e55\u7684\u89e6\u6478\u4e8b\u4ef6\uff0c\u5c06\u5f53\u524d\u4e8b\u4ef6\u53d1\u751f\u7684\u5750\u6807\u6253\u5370\u5728TextView\u4e0a\uff1b<br \/>\n2.2\u3001\u5224\u65ad\u4e0d\u540c\u7684\u89e6\u6478\u4e8b\u4ef6\u7c7b\u578b\uff0c\u6539\u53d8TextView\u7684\u80cc\u5f71\u8272\uff1b<br \/>\n2.3\u3001\u5b9e\u73b0\u672c\u8eab\u5f88\u7b80\u5355\uff0c\u5bf9\u4e8e\u521d\u5b66\u8005\u6765\u8bb2\u662f\u4e00\u6b65\u79ef\u7d2f\uff0c\u4ee3\u7801\u4e2d\u6709\u76f8\u5bf9\u5e94\u6ce8\u91ca\u8bf4\u660e\uff1b<\/p>\n<p>3\u3001\u5173\u952e\u4ee3\u7801<br \/>\nXML<\/p>\n<pre line=\"1\" lang=\"java\"><?xml version=\"1.0\" encoding=\"utf-8\"?>\n<LinearLayout 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:orientation=\"vertical\"\n    tools:context=\"com.yusian.even.MainActivity\">\n\n    <TextView\n        android:id=\"@+id\/textView\"\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:text=\"Hello World!\"\n        android:layout_margin=\"20dp\"\n        android:layout_gravity=\"center_horizontal\"\/>\n\n<\/LinearLayout><\/pre>\n<p><!--more--><br \/>\nActivity<\/p>\n<pre line=\"1\" lang=\"java\">package com.yusian.even;\n\nimport android.graphics.Color;\nimport android.support.v7.app.AppCompatActivity;\nimport android.os.Bundle;\nimport android.util.Log;\nimport android.view.MotionEvent;\nimport android.widget.TextView;\n\npublic class MainActivity extends AppCompatActivity {\n    private TextView textView;\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_main);\n        textView = (TextView)findViewById(R.id.textView);\n    }\n\n    @Override\n    \/\/ \u5b9e\u73b0Activity\u7684onTouchEvent\u65b9\u6cd5\u5373\u53ef\u76d1\u542c\u5f53\u524dActivity\u7684\u5c4f\u5e55\u4e8b\u4ef6\n    \/\/ MotionEvent\u7684\u4e09\u4e2a\u91cd\u8981\u65b9\u6cd5getAction()\u548cgetX()\u548cgetY()\n    public boolean onTouchEvent(MotionEvent event) {\n        \/\/ \u901a\u8fc7getAction()\u65b9\u6cd5\uff0c\u5b9e\u73b0\u5728\u6309\u4e0b\u4e0e\u62ac\u8d77\u65f6\u4e0d\u540c\u5904\u7406\n        if(event.getAction() == MotionEvent.ACTION_DOWN){\n            textView.setBackgroundColor(Color.GRAY);\n        }\n        if(event.getAction() == MotionEvent.ACTION_UP){\n            textView.setBackgroundColor(Color.YELLOW);\n        }\n        \/\/ \u4fee\u6539TextView\u6587\u5b57\uff0c\u663e\u793a\u5f53\u524d\u70b9\u51fb\u7684x\u3001y\u503c\n        textView.setText(\"X = \"+event.getX()+\"; Y = \"+event.getY());\n        return super.onTouchEvent(event);\n    }\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001\u4e0a\u56fe\uff0c\u65e0\u56fe\u65e0\u771f\u76f8 2\u3001Demo\u57fa\u672c\u8bbe\u8ba1\u539f\u7406 2.1\u3001\u76d1\u542c\u5c4f\u5e55\u7684\u89e6\u6478\u4e8b\u4ef6\uff0c\u5c06\u5f53\u524d\u4e8b\u4ef6\u53d1\u751f\u7684\u5750\u6807\u6253\u5370\u5728TextView\u4e0a\uff1b 2.2\u3001\u5224\u65ad\u4e0d\u540c\u7684\u89e6\u6478\u4e8b\u4ef6\u7c7b\u578b\uff0c\u6539\u53d8TextView\u7684\u80cc\u5f71\u8272\uff1b 2.3\u3001\u5b9e\u73b0\u672c\u8eab\u5f88\u7b80\u5355\uff0c\u5bf9\u4e8e\u521d\u5b66\u8005\u6765\u8bb2\u662f\u4e00\u6b65\u79ef\u7d2f\uff0c\u4ee3\u7801\u4e2d\u6709\u76f8\u5bf9\u5e94\u6ce8\u91ca\u8bf4\u660e\uff1b 3\u3001\u5173\u952e\u4ee3\u7801 XML<\/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-901","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\/901","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=901"}],"version-history":[{"count":0,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/901\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/media?parent=901"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/categories?post=901"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/tags?post=901"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}