{"id":15634,"date":"2025-04-29T16:51:43","date_gmt":"2025-04-29T08:51:43","guid":{"rendered":"http:\/\/xinyiworld.top\/wordpress_it\/?p=15634"},"modified":"2025-04-30T21:17:45","modified_gmt":"2025-04-30T13:17:45","slug":"%e6%95%b0%e5%9d%a4%e8%b6%85%e5%a3%b0%e5%8a%a9%e6%89%8b%e9%a1%b9%e7%9b%ae","status":"publish","type":"post","link":"http:\/\/xinyiworld.top\/wordpress_it\/?p=15634","title":{"rendered":"\u6570\u5764\u8d85\u58f0\u52a9\u624b\u9879\u76ee\u6ed1\u52a8\u51b2\u7a81"},"content":{"rendered":"<h1>\u4e00\u3001\u9700\u6c42<\/h1>\n<p><img src=\"http:\/\/xinyiworld.top\/wordpress_it\/wp-content\/uploads\/2025\/04\/\u5fae\u4fe1\u56fe\u7247_20250429180912.png\" alt=\"\" \/><\/p>\n<p>A:\u7ea2\u8272\u77e9\u5f62\u6846\u4e3a\u60ac\u6d6e\u7a97\uff0c\u8981\u6c42\u80fd\u5728\u684c\u9762\u505a\u751f\u610f\u62d6\u52a8\u4f46\u4e0d\u8d85\u51fa\u684c\u9762\u3002<\/p>\n<p>B:\u9171\u8272\u77e9\u5f62\u6846\uff0c\u8981\u6c42\u70b9\u51fb\u53ef\u6298\u53e0\/\u5c55\u5f00\u6a58\u9ec4\u8272+\u7d2b\u8272\u6846\u7684\u533a\u57df\uff1b\u5982\u679c\u662f\u62d6\u52a8\uff0c\u9700\u8981\u4f18\u5148\u4e8e\u70b9\u51fb\u4e8b\u4ef6\uff0c\u62d6\u52a8\u6574\u4e2a\u60ac\u6d6e\u7a97\u3002<\/p>\n<p>C:\u5217\u8868\uff0c\u9700\u8981\u4e0a\u4e0b\u6ed1\u52a8\u3002\u4f46\u662f\u5de6\u53f3\u6ed1\u52a8\u65f6\u5219\u62d6\u52a8\u6574\u4e2a\u60ac\u6d6e\u7a97\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5178\u578b\u7684<strong>\u62d6\u52a8+\u70b9\u51fb+\u6ed1\u52a8<\/strong>\u4e8b\u4ef6\u51b2\u7a81\u7684\u573a\u666f\uff0cA\u4e3aCustomOverlayLinearLayout\uff0cB\u4e3aCustomTouchHandleImageView\uff0cC\u4e3aRecyclerView\u3002<\/p>\n<h1>\u4e8c\u3001\u4e8b\u4ef6\u4f20\u9012\u7684\u987a\u5e8f<\/h1>\n<p>1\uff09\u6700\u5f00\u59cb\u7684\u65f6\u5019\u53ea\u6709A\uff0c\u901a\u8fc7\u590d\u5199onTouch\u65b9\u6cd5\u6216\u8005\u8c03\u7528setOnTouchListener\u8bbe\u7f6e\uff0c\u53ef\u4ee5\u5b9e\u73b0\u60ac\u6d6e\u7a97A\u7684\u4efb\u610f\u62d6\u52a8\u3002<br \/>\n\u56e0\u4e3aCustomOverlayLinearLayout\u9ed8\u8ba4onInterceptTouchEvent\u65b9\u6cd5\u8fd4\u56defalse\uff0c\u5373\u4e0d\u62e6\u622a\u4e8b\u4ef6\uff0c\u4e8b\u4ef6\u5f80\u4e0b\u5c42\u5b50View\u4f20\u9012\uff0c\u4f46\u662f\u5b50View\u6ca1\u6709\u6d88\u8d39\u4e8b\u4ef6\uff0c\u6240\u4ee5\u6700\u7ec8\u4e8b\u4ef6\u5f97\u4ee5\u88abA\u7684onTouch\u65b9\u6cd5\u54cd\u5e94\u3002<\/p>\n<p>2\uff09\u63a5\u7740B\u52a0\u5230\u5e03\u5c40\uff0cB\u8bbe\u7f6e\u4e86\u4e00\u4e2a\u70b9\u51fb\u4e8b\u4ef6\u3002<br \/>\n\u7531\u4e8eB\u662f\u4e00\u4e2aView\uff0c\u5e76\u975eViewGroup\uff0c\u6240\u4ee5\u6ca1\u6709onInterceptTouchEvent\u65b9\u6cd5\uff0c\u76f4\u63a5\u70b9\u51fb\u4e8b\u4ef6\u6d88\u8d39\u4e86\u4e8b\u4ef6\uff0c\u89e6\u53d1\u81ea\u5df1\u7684\u70b9\u51fb\u4e8b\u4ef6\uff0c\u4e8b\u4ef6\u4fbf\u4e0d\u4f1a\u5411\u4e0a\u5206\u53d1\u81f3A\uff0c\u90a3\u4e48\u62d6\u52a8B\u5219A\u4e0d\u4f1a\u62d6\u52a8\u3002\u4f46\u662f\u4ea7\u54c1\u8981\u6c42B\u65e2\u80fd\u70b9\u51fb\u53c8\u80fd\u62d6\u52a8\uff0c\u600e\u4e48\u89e3\u51b3\uff1f<\/p>\n<p><strong>B\u65e2\u80fd\u70b9\u51fb\u53c8\u80fd\u62d6\u52a8<\/strong>\u6362\u4e00\u79cd\u8bf4\u6cd5\u5c31\u662f<strong>B\u8981\u6d88\u8d39\u70b9\u51fb\u4e8b\u4ef6\uff0c\u4f46\u662f\u4e0d\u6d88\u8d39MOVE\u4e8b\u4ef6\uff0c\u7531A\u6d88\u8d39MOVE\u4e8b\u4ef6\u5373\u53ef\u62d6\u52a8\u3002<\/strong><\/p>\n<p>\u4e0a\u9762\u5df2\u7ecf\u8bf4\u5230\u4e86<strong>CustomOverlayLinearLayout\u9ed8\u8ba4onInterceptTouchEvent\u65b9\u6cd5\u8fd4\u56defalse\uff0c\u5373\u4e0d\u62e6\u622a\u4e8b\u4ef6\uff0c\u4e8b\u4ef6\u5f80\u4e0b\u5c42\u5b50View\u4f20\u9012<\/strong>\uff0c\u73b0\u5728B\u6dfb\u52a0\u4e86\u70b9\u51fb\u4e8b\u4ef6\uff0c\u4f1a\u6d88\u8d39\u4e8b\u4ef6\uff0c\u90a3\u4e48\u81ea\u7136A\u6ca1\u6709\u6d88\u8d39\u4e8b\u4ef6\uff0c\u4f1a\u51fa\u73b0A\u62d6\u52a8\u5931\u6548\u7684\u95ee\u9898\uff0c\u6839\u672c\u539f\u56e0\u662fA\u6ca1\u6709\u6d88\u8d39\u4e8b\u4ef6\u3002<\/p>\n<blockquote>\n<p>A\u5982\u4f55\u6d88\u8d39\u4e8b\u4ef6<\/p>\n<\/blockquote>\n<p>\u9996\u5148\uff0cA\u662f\u4e00\u4e2aViewGroup\uff0c\u8981\u60f3\u6d88\u8d39\uff0c\u5148\u5f97\u62e6\u622a\u3002\u6240\u4ee5\u5f97\u590d\u5199onInterceptTouchEvent\u65b9\u6cd5\uff1a<br \/>\n\u8fd9\u91cc\u6709\u4e00\u4e2a\u4e8b\u4ef6\u5750\u6807\u4f4d\u79fb\u516c\u5f0f\uff0c\u6839\u636e\u4f4d\u79fb\u7684\u5927\u5c0f\u5224\u65ad\uff0c\u5982\u679c\u662fMOVE\u4e8b\u4ef6\u5219\u62e6\u622a\uff0c\u5bf9\u4e8e\u70b9\u51fb\u4e8b\u4ef6\u8981\u7ed9B\u653e\u884c\uff0c\u5426\u5219B\u7684\u70b9\u51fb\u4e8b\u4ef6\u4f1a\u5931\u6548\u3002<\/p>\n<pre><code> private var startX = 0f\n    private var startY = 0f\n    private val touchSlop = ViewConfiguration.get(context!!).scaledTouchSlop\n\n    override fun onInterceptTouchEvent(ev: MotionEvent): Boolean {\n        when (ev.action) {\n            MotionEvent.ACTION_DOWN -&gt; {\n                Log.d(TAG, &quot;onInterceptTouchEvent ACTION_DOWN&quot;)\n                startX = ev.x\n                startY = ev.y\n            }\n            MotionEvent.ACTION_MOVE -&gt; {\n                Log.d(TAG, &quot;onInterceptTouchEvent ACTION_MOVE&quot;)\n                val dx = ev.x - startX\n                val dy = ev.y - startY\n\n                if (dx * dx + dy * dy &gt; touchSlop * touchSlop) {\n                    \/\/2.\u5904\u7406\u4e0elogo\u70b9\u51fb\u4e8b\u4ef6\u51b2\u7a81\n                    return true \/\/ \u62e6\u622a\u4e8b\u4ef6\uff0c\u4ea4\u7ed9\u7236View\u5904\u7406\n                }\n            }\n            MotionEvent.ACTION_UP -&gt; {\n                Log.d(TAG, &quot;onInterceptTouchEvent ACTION_UP&quot;)\n            }\n        }\n        val onInterceptTouchEvent = super.onInterceptTouchEvent(ev)\n        Log.d(TAG, &quot;onInterceptTouchEvent: $onInterceptTouchEvent&quot;)\n        return onInterceptTouchEvent\n    }<\/code><\/pre>\n<p>3\uff09\u63a5\u7740C\u52a0\u5230\u5e03\u5c40\uff0cC\u6709\u5217\u8868\u6ed1\u52a8\u4e8b\u4ef6\u3002<br \/>\n\u540c\u7406\u4e5f\u662f\u590d\u5199A\u7684onInterceptTouchEvent\u65b9\u6cd5\uff0c\u5728 MotionEvent.ACTION_MOVE\u91cc\u52a0\u4e0a\u5224\u65ad\u5c31\u884c\uff1a<strong>\u53ea\u6709\u5c55\u5f00\u4e14\u7ad6\u5411\u6ed1\u52a8\u624d\u4e0d\u62e6\u622a\u4e8b\u4ef6<\/strong>\u3002<\/p>\n<pre><code> MotionEvent.ACTION_MOVE -&gt; {\n                Log.d(TAG, &quot;onInterceptTouchEvent ACTION_MOVE&quot;)\n                val dx = ev.x - startX\n                val dy = ev.y - startY\n\n                if (dx * dx + dy * dy &gt; touchSlop * touchSlop) {\n                    \/\/1.\u5904\u7406\u4e0eRecyclerView\u6ed1\u52a8\u51b2\u7a81\n                    if(expand){\n                        \/\/ \u5982\u679c\u662f\u7ad6\u5411\u6ed1\u52a8\uff0c\u5219\u4e0d\u62e6\u622a\u4e8b\u4ef6\uff0c\u4ea4\u7ed9 RecyclerView \u5904\u7406\n                        if (Math.abs(dy) &gt; Math.abs(dx)) {\n                            Log.d(TAG, &quot;onInterceptTouchEvent: \u4ea4\u7ed9 RecyclerView \u5904\u7406&quot;)\n                            return false\n                        }\n                    }else{\n                        Log.d(TAG, &quot;onInterceptTouchEvent: not expand&quot;)\n                    }\n\n                    \/\/2.\u5904\u7406\u4e0elogo\u70b9\u51fb\u4e8b\u4ef6\u51b2\u7a81\n                    return true \/\/ \u62e6\u622a\u4e8b\u4ef6\uff0c\u4ea4\u7ed9\u7236View\u5904\u7406\n                }\n            }<\/code><\/pre>\n<button class=\"simplefavorite-button\" data-postid=\"15634\" 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>\u4e00\u3001\u9700\u6c42 A:\u7ea2\u8272\u77e9\u5f62\u6846\u4e3a\u60ac\u6d6e\u7a97\uff0c\u8981\u6c42\u80fd\u5728\u684c\u9762\u505a\u751f\u610f\u62d6\u52a8\u4f46\u4e0d\u8d85\u51fa\u684c\u9762\u3002 B:\u9171\u8272\u77e9\u5f62\u6846\uff0c\u8981\u6c42\u70b9\u51fb\u53ef\u6298 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1186],"tags":[],"_links":{"self":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/15634"}],"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=15634"}],"version-history":[{"count":15,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/15634\/revisions"}],"predecessor-version":[{"id":15656,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/15634\/revisions\/15656"}],"wp:attachment":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=15634"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=15634"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=15634"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}