{"id":15645,"date":"2025-04-30T13:38:46","date_gmt":"2025-04-30T05:38:46","guid":{"rendered":"http:\/\/xinyiworld.top\/wordpress_it\/?p=15645"},"modified":"2025-06-09T11:12:09","modified_gmt":"2025-06-09T03:12:09","slug":"%e5%bc%84%e6%87%82%e4%ba%8b%e4%bb%b6%e5%88%86%e5%8f%91%e5%bf%85%e9%9c%80%e8%a6%81%e6%8e%8c%e6%8f%a1%e7%9a%84%e5%b8%b8%e8%af%86","status":"publish","type":"post","link":"http:\/\/xinyiworld.top\/wordpress_it\/?p=15645","title":{"rendered":"\u5f04\u61c2\u4e8b\u4ef6\u5206\u53d1\u5fc5\u9700\u8981\u638c\u63e1\u7684\u5e38\u8bc6"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_16 counter-hierarchy counter-decimal ez-toc-grey\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\">\u76ee\u5f55<\/p>\n<span class=\"ez-toc-title-toggle\"><a class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" style=\"display: none;\"><i class=\"ez-toc-glyphicon ez-toc-icon-toggle\"><\/i><\/a><\/span><\/div>\n<nav><ul class=\"ez-toc-list ez-toc-list-level-1\"><li class=\"ez-toc-page-1 ez-toc-heading-level-1\"><a class=\"ez-toc-link ez-toc-heading-1\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=15645\/#1%E5%85%B3%E4%BA%8EViewGroup_%E7%9A%84_onInterceptTouchEvent%E6%96%B9%E6%B3%95\" title=\"1.\u5173\u4e8eViewGroup \u7684 onInterceptTouchEvent()\u65b9\u6cd5\">1.\u5173\u4e8eViewGroup \u7684 onInterceptTouchEvent()\u65b9\u6cd5<\/a><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-2\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=15645\/#%E5%93%AA%E4%BA%9B_ViewGroup_%E5%8F%AF%E8%83%BD_%E4%BC%9A%E6%8B%A6%E6%88%AA%E8%A7%A6%E6%91%B8%E4%BA%8B%E4%BB%B6%EF%BC%9F\" title=\"\u54ea\u4e9b ViewGroup \u53ef\u80fd \u4f1a\u62e6\u622a\u89e6\u6478\u4e8b\u4ef6\uff1f\">\u54ea\u4e9b ViewGroup \u53ef\u80fd \u4f1a\u62e6\u622a\u89e6\u6478\u4e8b\u4ef6\uff1f<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-3\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=15645\/#%E4%B8%BA%E4%BB%80%E4%B9%88%E6%B2%A1%E6%9C%89_ViewGroup_%E9%BB%98%E8%AE%A4%E8%BF%94%E5%9B%9E_true%EF%BC%9F\" title=\"\u4e3a\u4ec0\u4e48\u6ca1\u6709 ViewGroup \u9ed8\u8ba4\u8fd4\u56de true\uff1f\">\u4e3a\u4ec0\u4e48\u6ca1\u6709 ViewGroup \u9ed8\u8ba4\u8fd4\u56de true\uff1f<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-4\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=15645\/#%E5%A6%82%E4%BD%95%E8%AE%A9%E8%87%AA%E5%AE%9A%E4%B9%89_ViewGroup_%E9%BB%98%E8%AE%A4%E6%8B%A6%E6%88%AA%E4%BA%8B%E4%BB%B6%EF%BC%9F\" title=\"\u5982\u4f55\u8ba9\u81ea\u5b9a\u4e49 ViewGroup \u9ed8\u8ba4\u62e6\u622a\u4e8b\u4ef6\uff1f\">\u5982\u4f55\u8ba9\u81ea\u5b9a\u4e49 ViewGroup \u9ed8\u8ba4\u62e6\u622a\u4e8b\u4ef6\uff1f<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-5\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=15645\/#%E6%80%BB%E7%BB%93\" title=\"\u603b\u7ed3\">\u603b\u7ed3<\/a><\/li><\/ul><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-1\"><a class=\"ez-toc-link ez-toc-heading-6\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=15645\/#2onInterceptTouchEvent%E4%BA%8B%E4%BB%B6%E6%B5%81%E7%9A%84%E4%B8%80%E8%87%B4%E6%80%A7\" title=\"2.onInterceptTouchEvent\u4e8b\u4ef6\u6d41\u7684\u4e00\u81f4\u6027\">2.onInterceptTouchEvent\u4e8b\u4ef6\u6d41\u7684\u4e00\u81f4\u6027<\/a><ul class=\"ez-toc-list-level-2\"><li class=\"ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-7\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=15645\/#1_%E4%BA%8B%E4%BB%B6%E5%88%86%E5%8F%91%E7%9A%84%E5%9F%BA%E6%9C%AC%E6%B5%81%E7%A8%8B\" title=\"1. \u4e8b\u4ef6\u5206\u53d1\u7684\u57fa\u672c\u6d41\u7a0b\">1. \u4e8b\u4ef6\u5206\u53d1\u7684\u57fa\u672c\u6d41\u7a0b<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-8\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=15645\/#2_%E4%B8%BA%E4%BB%80%E4%B9%88_ACTION_UP_%E4%B8%8D%E5%86%8D%E7%BB%8F%E8%BF%87_onInterceptTouchEvent%EF%BC%9F\" title=\"2. \u4e3a\u4ec0\u4e48 ACTION_UP \u4e0d\u518d\u7ecf\u8fc7 onInterceptTouchEvent\uff1f\">2. \u4e3a\u4ec0\u4e48 ACTION_UP \u4e0d\u518d\u7ecf\u8fc7 onInterceptTouchEvent\uff1f<\/a><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-1\"><a class=\"ez-toc-link ez-toc-heading-9\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=15645\/#3setOnClickListener%E3%80%81onTouchEvent_%E5%92%8C_setOnTouchListener_%E4%B8%89%E8%80%85%E4%B9%8B%E9%97%B4%E7%9A%84%E5%85%B3%E7%B3%BB\" title=\"3.setOnClickListener\u3001onTouchEvent \u548c setOnTouchListener \u4e09\u8005\u4e4b\u95f4\u7684\u5173\u7cfb\">3.setOnClickListener\u3001onTouchEvent \u548c setOnTouchListener \u4e09\u8005\u4e4b\u95f4\u7684\u5173\u7cfb<\/a><ul class=\"ez-toc-list-level-2\"><li class=\"ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-10\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=15645\/#1_%E4%B8%89%E8%80%85%E7%9A%84%E4%BD%9C%E7%94%A8\" title=\"1. \u4e09\u8005\u7684\u4f5c\u7528\">1. \u4e09\u8005\u7684\u4f5c\u7528<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-11\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=15645\/#2_%E6%89%A7%E8%A1%8C%E9%A1%BA%E5%BA%8F\" title=\"2. \u6267\u884c\u987a\u5e8f\">2. \u6267\u884c\u987a\u5e8f<\/a><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-12\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=15645\/#%E4%BC%AA%E4%BB%A3%E7%A0%81%E9%80%BB%E8%BE%91\" title=\"\u4f2a\u4ee3\u7801\u903b\u8f91\">\u4f2a\u4ee3\u7801\u903b\u8f91<\/a><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-13\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=15645\/#3_%E5%85%B3%E9%94%AE%E5%8C%BA%E5%88%AB\" title=\"3. \u5173\u952e\u533a\u522b\">3. \u5173\u952e\u533a\u522b<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"1%E5%85%B3%E4%BA%8EViewGroup_%E7%9A%84_onInterceptTouchEvent%E6%96%B9%E6%B3%95\"><\/span>1.\u5173\u4e8eViewGroup \u7684 onInterceptTouchEvent()\u65b9\u6cd5<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p><em>from deepseek<\/em>:<\/p>\n<p>\u5728 Android \u4e2d\uff0c<strong>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6240\u6709 ViewGroup \u7684 <code>onInterceptTouchEvent()<\/code> \u90fd\u8fd4\u56de <code>false<\/code><\/strong>\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u4eec\u9ed8\u8ba4\u4e0d\u4f1a\u62e6\u622a\u89e6\u6478\u4e8b\u4ef6\uff0c\u800c\u662f\u5c06\u4e8b\u4ef6\u4f20\u9012\u7ed9\u5b50 View \u5904\u7406\u3002<\/p>\n<p>\u4f46\u6709\u4e00\u4e9b <strong>\u7279\u6b8a ViewGroup<\/strong> \u4f1a\u6839\u636e\u89e6\u6478\u884c\u4e3a\u52a8\u6001\u51b3\u5b9a\u662f\u5426\u62e6\u622a\u4e8b\u4ef6\uff08\u4f8b\u5982 <code>ScrollView<\/code>\u3001<code>RecyclerView<\/code>\u3001<code>ViewPager<\/code> \u7b49\uff09\uff0c\u4f46\u5b83\u4eec\u4ecd\u7136\u4e0d\u4f1a\u5728 <code>onInterceptTouchEvent()<\/code> \u7684<strong>\u9ed8\u8ba4\u5b9e\u73b0<\/strong>\u4e2d\u76f4\u63a5\u8fd4\u56de <code>true<\/code>\uff0c\u800c\u662f\u5728\u7279\u5b9a\u6761\u4ef6\u4e0b\uff08\u5982\u68c0\u6d4b\u5230\u6ed1\u52a8\uff09\u624d\u8fd4\u56de <code>true<\/code> \u4ee5\u62e6\u622a\u4e8b\u4ef6\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E5%93%AA%E4%BA%9B_ViewGroup_%E5%8F%AF%E8%83%BD_%E4%BC%9A%E6%8B%A6%E6%88%AA%E8%A7%A6%E6%91%B8%E4%BA%8B%E4%BB%B6%EF%BC%9F\"><\/span>\u54ea\u4e9b ViewGroup <strong>\u53ef\u80fd<\/strong> \u4f1a\u62e6\u622a\u89e6\u6478\u4e8b\u4ef6\uff1f<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u867d\u7136\u9ed8\u8ba4\u8fd4\u56de <code>false<\/code>\uff0c\u4f46\u4ee5\u4e0b ViewGroup \u4f1a\u5728\u7279\u5b9a\u6761\u4ef6\u4e0b\u62e6\u622a\u4e8b\u4ef6\uff1a<\/p>\n<ol>\n<li><strong><code>ScrollView<\/code> \/ <code>HorizontalScrollView<\/code><\/strong>\n<ul>\n<li>\u5f53\u68c0\u6d4b\u5230\u5782\u76f4\/\u6c34\u5e73\u6ed1\u52a8\u65f6\uff0c<code>onInterceptTouchEvent()<\/code> \u4f1a\u8fd4\u56de <code>true<\/code>\uff0c\u62e6\u622a\u4e8b\u4ef6\u4ee5\u5904\u7406\u6eda\u52a8\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong><code>RecyclerView<\/code> \/ <code>ListView<\/code><\/strong>\n<ul>\n<li>\u5f53\u68c0\u6d4b\u5230\u6ed1\u52a8\u65f6\uff0c\u4f1a\u62e6\u622a\u4e8b\u4ef6\u4ee5\u5904\u7406\u6eda\u52a8\uff0c\u5426\u5219\u4ea4\u7ed9\u5b50\u9879\u5904\u7406\u70b9\u51fb\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong><code>ViewPager<\/code> \/ <code>ViewPager2<\/code><\/strong>\n<ul>\n<li>\u5f53\u68c0\u6d4b\u5230\u6c34\u5e73\u6ed1\u52a8\u65f6\uff0c\u4f1a\u62e6\u622a\u4e8b\u4ef6\u4ee5\u5904\u7406\u7ffb\u9875\uff0c\u5426\u5219\u4ea4\u7ed9\u5b50 View \u5904\u7406\u70b9\u51fb\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong><code>NestedScrollView<\/code><\/strong>\n<ul>\n<li>\u7c7b\u4f3c <code>ScrollView<\/code>\uff0c\u4f46\u652f\u6301\u5d4c\u5957\u6eda\u52a8\uff0c\u4f1a\u5728\u9002\u5f53\u6761\u4ef6\u4e0b\u62e6\u622a\u4e8b\u4ef6\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong><code>DrawerLayout<\/code><\/strong>\n<ul>\n<li>\u5f53\u68c0\u6d4b\u5230\u8fb9\u7f18\u6ed1\u52a8\u65f6\uff0c\u4f1a\u62e6\u622a\u4e8b\u4ef6\u4ee5\u6253\u5f00\u62bd\u5c49\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3><span class=\"ez-toc-section\" id=\"%E4%B8%BA%E4%BB%80%E4%B9%88%E6%B2%A1%E6%9C%89_ViewGroup_%E9%BB%98%E8%AE%A4%E8%BF%94%E5%9B%9E_true%EF%BC%9F\"><\/span>\u4e3a\u4ec0\u4e48\u6ca1\u6709 ViewGroup \u9ed8\u8ba4\u8fd4\u56de <code>true<\/code>\uff1f<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>\u5982\u679c <code>onInterceptTouchEvent()<\/code> \u9ed8\u8ba4\u8fd4\u56de <code>true<\/code>\uff0c\u90a3\u4e48\u6240\u6709\u89e6\u6478\u4e8b\u4ef6\u90fd\u4f1a\u88ab\u7236 View \u62e6\u622a\uff0c\u5b50 View \u5c06\u65e0\u6cd5\u63a5\u6536\u4efb\u4f55\u4e8b\u4ef6\uff0c\u8fd9\u663e\u7136\u4e0d\u7b26\u5408\u5927\u591a\u6570 UI \u4ea4\u4e92\u9700\u6c42\u3002<\/li>\n<li>\u901a\u5e38\uff0c\u62e6\u622a\u903b\u8f91\u662f<strong>\u52a8\u6001\u7684<\/strong>\uff0c\u4f8b\u5982\uff1a\n<ul>\n<li>\u5982\u679c\u7528\u6237<strong>\u70b9\u51fb<\/strong>\uff0c\u4e0d\u62e6\u622a\uff08\u4ea4\u7ed9\u5b50 View \u5904\u7406\uff09\u3002<\/li>\n<li>\u5982\u679c\u7528\u6237<strong>\u6ed1\u52a8<\/strong>\uff0c\u62e6\u622a\uff08\u7236 View \u5904\u7406\u6eda\u52a8\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"%E5%A6%82%E4%BD%95%E8%AE%A9%E8%87%AA%E5%AE%9A%E4%B9%89_ViewGroup_%E9%BB%98%E8%AE%A4%E6%8B%A6%E6%88%AA%E4%BA%8B%E4%BB%B6%EF%BC%9F\"><\/span>\u5982\u4f55\u8ba9\u81ea\u5b9a\u4e49 ViewGroup \u9ed8\u8ba4\u62e6\u622a\u4e8b\u4ef6\uff1f<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u5982\u679c\u4f60\u60f3\u8ba9\u4f60\u7684 <code>ViewGroup<\/code> \u9ed8\u8ba4\u62e6\u622a\u6240\u6709\u89e6\u6478\u4e8b\u4ef6\uff08\u7c7b\u4f3c <code>return true<\/code>\uff09\uff0c\u53ef\u4ee5\u8fd9\u6837\uff1a<\/p>\n<pre><code>override fun onInterceptTouchEvent(ev: MotionEvent): Boolean {\n    return true \/\/ \u62e6\u622a\u6240\u6709\u4e8b\u4ef6\uff0c\u5b50 View \u65e0\u6cd5\u6536\u5230\u4efb\u4f55\u89e6\u6478\u4e8b\u4ef6\n}<\/code><\/pre>\n<p>\u4f46\u8fd9\u6837\u505a\u4f1a\u5bfc\u81f4\u5b50 View <strong>\u5b8c\u5168\u65e0\u6cd5\u54cd\u5e94\u89e6\u6478<\/strong>\uff0c\u901a\u5e38\u53ea\u9002\u7528\u4e8e\u7279\u6b8a\u573a\u666f\uff08\u5982\u5168\u5c4f\u62e6\u622a\u624b\u52bf\uff09\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E6%80%BB%E7%BB%93\"><\/span>\u603b\u7ed3<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li><strong>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6240\u6709 <code>ViewGroup<\/code> \u7684 <code>onInterceptTouchEvent()<\/code> \u8fd4\u56de <code>false<\/code><\/strong>\u3002<\/li>\n<li><strong>\u67d0\u4e9b <code>ViewGroup<\/code>\uff08\u5982 <code>ScrollView<\/code>\u3001<code>RecyclerView<\/code>\uff09\u4f1a\u5728\u6ed1\u52a8\u65f6\u52a8\u6001\u8fd4\u56de <code>true<\/code><\/strong> \u4ee5\u62e6\u622a\u4e8b\u4ef6\u3002<\/li>\n<li>\u5982\u679c\u9700\u8981\u5f3a\u5236\u62e6\u622a\uff0c\u53ef\u4ee5\u624b\u52a8\u91cd\u5199 <code>onInterceptTouchEvent()<\/code> \u8fd4\u56de <code>true<\/code>\uff0c\u4f46\u901a\u5e38\u4e0d\u5efa\u8bae\u8fd9\u6837\u505a\uff0c\u9664\u975e\u6709\u7279\u6b8a\u9700\u6c42\u3002<\/li>\n<\/ul>\n<h1><span class=\"ez-toc-section\" id=\"2onInterceptTouchEvent%E4%BA%8B%E4%BB%B6%E6%B5%81%E7%9A%84%E4%B8%80%E8%87%B4%E6%80%A7\"><\/span>2.onInterceptTouchEvent\u4e8b\u4ef6\u6d41\u7684\u4e00\u81f4\u6027<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>\u95ee\u9898\uff1a<br \/>\n<code>\u4e3a\u4ec0\u4e48ViewGroup\u7684onInterceptTouchEvent  MotionEvent.ACTION_MOVE return true\u4e4b\u540e\uff0conInterceptTouchEvent \u6536\u4e0d\u5230MotionEvent.ACTION_UP\u4e8b\u4ef6\uff0c\u76f4\u63a5\u5c31\u8c03\u7528\u4e86ViewGroup\u7684setOnTouchListener onTouch\u65b9\u6cd5\u7684MotionEvent.ACTION_UP\uff1f<\/code><\/p>\n<h2><span class=\"ez-toc-section\" id=\"1_%E4%BA%8B%E4%BB%B6%E5%88%86%E5%8F%91%E7%9A%84%E5%9F%BA%E6%9C%AC%E6%B5%81%E7%A8%8B\"><\/span><strong>1. \u4e8b\u4ef6\u5206\u53d1\u7684\u57fa\u672c\u6d41\u7a0b<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Android \u7684\u89e6\u6478\u4e8b\u4ef6\u5206\u53d1\u9075\u5faa\u4ee5\u4e0b\u987a\u5e8f\uff1a<\/p>\n<ol>\n<li><strong><code>ViewGroup.dispatchTouchEvent()<\/code><\/strong>\uff08\u4e8b\u4ef6\u5206\u53d1\u5165\u53e3\uff09<\/li>\n<li><strong><code>ViewGroup.onInterceptTouchEvent()<\/code><\/strong>\uff08\u51b3\u5b9a\u662f\u5426\u62e6\u622a\u4e8b\u4ef6\uff09\n<ul>\n<li>\u9ed8\u8ba4\u8fd4\u56de <code>false<\/code>\uff0c\u4e0d\u62e6\u622a\uff0c\u4e8b\u4ef6\u7ee7\u7eed\u5206\u53d1\u7ed9\u5b50 View\u3002<\/li>\n<li>\u5982\u679c\u8fd4\u56de <code>true<\/code>\uff0c\u540e\u7eed\u4e8b\u4ef6\uff08\u5305\u62ec <code>ACTION_MOVE<\/code>\u3001<code>ACTION_UP<\/code>\uff09\u76f4\u63a5\u4ea4\u7ed9 <code>ViewGroup<\/code> \u5904\u7406\uff0c\u4e0d\u518d\u8be2\u95ee <code>onInterceptTouchEvent<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong><code>View.onTouchEvent()<\/code> \u6216 <code>OnTouchListener.onTouch()<\/code><\/strong>\uff08\u5904\u7406\u89e6\u6478\u4e8b\u4ef6\uff09<\/li>\n<\/ol>\n<hr \/>\n<h2><span class=\"ez-toc-section\" id=\"2_%E4%B8%BA%E4%BB%80%E4%B9%88_ACTION_UP_%E4%B8%8D%E5%86%8D%E7%BB%8F%E8%BF%87_onInterceptTouchEvent%EF%BC%9F\"><\/span><strong>2. \u4e3a\u4ec0\u4e48 <code>ACTION_UP<\/code> \u4e0d\u518d\u7ecf\u8fc7 <code>onInterceptTouchEvent<\/code>\uff1f<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u5f53 <code>onInterceptTouchEvent<\/code> \u5728 <code>ACTION_MOVE<\/code> \u65f6\u8fd4\u56de <code>true<\/code>\uff1a<\/p>\n<ul>\n<li><strong>\u8868\u793a <code>ViewGroup<\/code> \u5df2\u7ecf\u51b3\u5b9a\u63a5\u7ba1\u540e\u7eed\u6240\u6709\u4e8b\u4ef6<\/strong>\uff08\u5305\u62ec <code>ACTION_UP<\/code>\uff09\u3002<\/li>\n<li>\u7cfb\u7edf\u4f1a\u76f4\u63a5\u8c03\u7528 <code>ViewGroup<\/code> \u7684 <code>onTouch<\/code> \u6216 <code>onTouchEvent<\/code>\uff0c\u800c\u4e0d\u4f1a\u518d\u8be2\u95ee <code>onInterceptTouchEvent<\/code>\uff0c\u56e0\u4e3a\uff1a\n<ol>\n<li><strong>\u907f\u514d\u91cd\u590d\u5224\u65ad<\/strong>\uff1a\u65e2\u7136 <code>ViewGroup<\/code> \u5df2\u7ecf\u51b3\u5b9a\u62e6\u622a\uff0c\u540e\u7eed\u4e8b\u4ef6\u65e0\u9700\u518d\u6b21\u8be2\u95ee\u3002<\/li>\n<li><strong>\u4fdd\u6301\u4e8b\u4ef6\u6d41\u4e00\u81f4\u6027<\/strong>\uff1a\u5982\u679c <code>ACTION_UP<\/code> \u53c8\u7a81\u7136\u4e0d\u62e6\u622a\uff0c\u4f1a\u5bfc\u81f4\u4e8b\u4ef6\u903b\u8f91\u6df7\u4e71\u3002<\/li>\n<li><strong>\u6027\u80fd\u4f18\u5316<\/strong>\uff1a\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684 <code>onInterceptTouchEvent<\/code> \u8c03\u7528\u3002<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<h1><span class=\"ez-toc-section\" id=\"3setOnClickListener%E3%80%81onTouchEvent_%E5%92%8C_setOnTouchListener_%E4%B8%89%E8%80%85%E4%B9%8B%E9%97%B4%E7%9A%84%E5%85%B3%E7%B3%BB\"><\/span>3.setOnClickListener\u3001onTouchEvent \u548c setOnTouchListener \u4e09\u8005\u4e4b\u95f4\u7684\u5173\u7cfb<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<hr \/>\n<h2><span class=\"ez-toc-section\" id=\"1_%E4%B8%89%E8%80%85%E7%9A%84%E4%BD%9C%E7%94%A8\"><\/span><strong>1. \u4e09\u8005\u7684\u4f5c\u7528<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: left;\">\u65b9\u6cd5\/Listener<\/th>\n<th style=\"text-align: left;\">\u4f5c\u7528<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: left;\"><strong><code>setOnClickListener<\/code><\/strong><\/td>\n<td style=\"text-align: left;\">\u7528\u4e8e\u5904\u7406 <strong>\u70b9\u51fb\u4e8b\u4ef6<\/strong>\uff08<code>ACTION_UP<\/code> \u65f6\u89e6\u53d1\uff0c\u9700\u6ee1\u8db3\u70b9\u51fb\u6761\u4ef6\uff09\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><strong><code>setOnTouchListener<\/code><\/strong><\/td>\n<td style=\"text-align: left;\">\u7528\u4e8e\u76d1\u542c <strong>\u6240\u6709\u89e6\u6478\u4e8b\u4ef6<\/strong>\uff08<code>ACTION_DOWN<\/code>\u3001<code>ACTION_MOVE<\/code>\u3001<code>ACTION_UP<\/code>\uff09\uff0c<strong>\u4f18\u5148\u7ea7\u9ad8\u4e8e <code>onTouchEvent<\/code><\/strong>\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><strong><code>onTouchEvent<\/code><\/strong><\/td>\n<td style=\"text-align: left;\">View \u7684\u9ed8\u8ba4\u89e6\u6478\u4e8b\u4ef6\u5904\u7406\u65b9\u6cd5\uff0c\u5982\u679c <code>OnTouchListener<\/code> \u6ca1\u6709\u6d88\u8d39\u4e8b\u4ef6\uff0c\u5219\u4f1a\u8c03\u7528\u5b83\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h2><span class=\"ez-toc-section\" id=\"2_%E6%89%A7%E8%A1%8C%E9%A1%BA%E5%BA%8F\"><\/span><strong>2. \u6267\u884c\u987a\u5e8f<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u5f53\u7528\u6237\u89e6\u6478\u5c4f\u5e55\u65f6\uff0c\u4e8b\u4ef6\u4f20\u9012\u7684\u987a\u5e8f\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li><strong><code>dispatchTouchEvent<\/code><\/strong>\uff08View \u7684\u4e8b\u4ef6\u5206\u53d1\u5165\u53e3\uff09<\/li>\n<li><strong><code>OnTouchListener.onTouch()<\/code><\/strong>\uff08\u5982\u679c\u8bbe\u7f6e\u4e86 <code>setOnTouchListener<\/code>\uff09\n<ul>\n<li>\u5982\u679c\u8fd4\u56de <code>true<\/code>\uff0c\u8868\u793a\u4e8b\u4ef6\u88ab\u6d88\u8d39\uff0c\u540e\u7eed <code>onTouchEvent<\/code> \u548c <code>OnClickListener<\/code> \u4e0d\u4f1a\u6267\u884c\u3002<\/li>\n<li>\u5982\u679c\u8fd4\u56de <code>false<\/code>\uff0c\u7ee7\u7eed\u6267\u884c <code>onTouchEvent<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong><code>onTouchEvent<\/code><\/strong>\uff08View \u7684\u9ed8\u8ba4\u89e6\u6478\u5904\u7406\uff09\n<ul>\n<li>\u5982\u679c <code>onTouchEvent<\/code> \u8fd4\u56de <code>true<\/code>\uff0c\u8868\u793a\u4e8b\u4ef6\u88ab\u6d88\u8d39\u3002<\/li>\n<li>\u5982\u679c <code>ACTION_UP<\/code> \u6ee1\u8db3\u70b9\u51fb\u6761\u4ef6\uff0c\u4e14 <code>OnTouchListener<\/code> \u672a\u62e6\u622a\uff0c\u5219\u89e6\u53d1 <code>OnClickListener<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong><code>OnClickListener.onClick()<\/code><\/strong>\uff08\u5982\u679c\u8bbe\u7f6e\u4e86 <code>setOnClickListener<\/code>\uff09<\/li>\n<\/ol>\n<h3><span class=\"ez-toc-section\" id=\"%E4%BC%AA%E4%BB%A3%E7%A0%81%E9%80%BB%E8%BE%91\"><\/span><strong>\u4f2a\u4ee3\u7801\u903b\u8f91<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre><code>fun dispatchTouchEvent(event: MotionEvent): Boolean {\n    if (onTouchListener?.onTouch(this, event) == true) {\n        return true \/\/ OnTouchListener \u6d88\u8d39\u4e86\u4e8b\u4ef6\uff0c\u4e0d\u518d\u6267\u884c\u540e\u7eed\u903b\u8f91\n    }\n    if (onTouchEvent(event)) {\n        return true \/\/ onTouchEvent \u6d88\u8d39\u4e86\u4e8b\u4ef6\n    }\n    return false \/\/ \u4e8b\u4ef6\u672a\u88ab\u6d88\u8d39\n}\n\nfun onTouchEvent(event: MotionEvent): Boolean {\n    when (event.action) {\n        ACTION_UP -&gt; {\n            if (isClickable &amp;&amp; isInTouchBounds(event)) {\n                performClick() \/\/ \u89e6\u53d1 OnClickListener\n            }\n        }\n    }\n    return super.onTouchEvent(event)\n}<\/code><\/pre>\n<hr \/>\n<h2><span class=\"ez-toc-section\" id=\"3_%E5%85%B3%E9%94%AE%E5%8C%BA%E5%88%AB\"><\/span><strong>3. \u5173\u952e\u533a\u522b<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: left;\">\u5bf9\u6bd4\u9879<\/th>\n<th style=\"text-align: left;\"><code>setOnTouchListener<\/code><\/th>\n<th style=\"text-align: left;\"><code>onTouchEvent<\/code><\/th>\n<th style=\"text-align: left;\"><code>setOnClickListener<\/code><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: left;\"><strong>\u89e6\u53d1\u65f6\u673a<\/strong><\/td>\n<td style=\"text-align: left;\">\u6240\u6709\u89e6\u6478\u4e8b\u4ef6\uff08<code>DOWN<\/code>\u3001<code>MOVE<\/code>\u3001<code>UP<\/code>\uff09<\/td>\n<td style=\"text-align: left;\">\u6240\u6709\u89e6\u6478\u4e8b\u4ef6\uff08\u5982\u679c <code>OnTouchListener<\/code> \u672a\u6d88\u8d39\uff09<\/td>\n<td style=\"text-align: left;\">\u4ec5 <code>ACTION_UP<\/code> \u4e14\u7b26\u5408\u70b9\u51fb\u6761\u4ef6<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><strong>\u8fd4\u56de\u503c\u5f71\u54cd<\/strong><\/td>\n<td style=\"text-align: left;\">\u8fd4\u56de <code>true<\/code> \u4f1a\u62e6\u622a\u540e\u7eed\u4e8b\u4ef6<\/td>\n<td style=\"text-align: left;\">\u8fd4\u56de <code>true<\/code> \u8868\u793a\u6d88\u8d39\u4e8b\u4ef6<\/td>\n<td style=\"text-align: left;\">\u65e0\u8fd4\u56de\u503c<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><strong>\u4f18\u5148\u7ea7<\/strong><\/td>\n<td style=\"text-align: left;\">\u6700\u9ad8\uff08\u5148\u6267\u884c\uff09<\/td>\n<td style=\"text-align: left;\">\u6b21\u4e4b<\/td>\n<td style=\"text-align: left;\">\u6700\u4f4e\uff08\u6700\u540e\u6267\u884c\uff09<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><strong>\u9002\u7528\u573a\u666f<\/strong><\/td>\n<td style=\"text-align: left;\">\u9700\u8981\u7cbe\u7ec6\u63a7\u5236\u89e6\u6478\u903b\u8f91\uff08\u5982\u6ed1\u52a8\u3001\u957f\u6309\uff09<\/td>\n<td style=\"text-align: left;\">\u81ea\u5b9a\u4e49 View \u7684\u9ed8\u8ba4\u89e6\u6478\u5904\u7406<\/td>\n<td style=\"text-align: left;\">\u7b80\u5355\u70b9\u51fb\u4ea4\u4e92<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<button class=\"simplefavorite-button\" data-postid=\"15645\" data-siteid=\"1\" data-groupid=\"1\" data-favoritecount=\"0\" style=\"\">\u6536\u85cf <i class=\"sf-icon-star-empty\"><\/i><\/button>","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55 1.\u5173\u4e8eViewGroup \u7684 onInterceptTouchEvent()\u65b9\u6cd5\u54ea\u4e9b Vie [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1185],"tags":[],"_links":{"self":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/15645"}],"collection":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=15645"}],"version-history":[{"count":5,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/15645\/revisions"}],"predecessor-version":[{"id":15702,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/15645\/revisions\/15702"}],"wp:attachment":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=15645"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=15645"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=15645"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}