{"id":13642459,"url":"https://github.com/mcxtzhang/SwipeDelMenuLayout","last_synced_at":"2025-04-20T16:32:23.760Z","repository":{"id":39175228,"uuid":"66538534","full_name":"mcxtzhang/SwipeDelMenuLayout","owner":"mcxtzhang","description":"The most simple SwipeMenu in the history, 0 coupling, support any ViewGroup. Step integration swipe (delete) menu, high imitation QQ, iOS. ~史上最简单侧滑菜单，0耦合，支持任意ViewGroup。一步集成侧滑(删除)菜单，高仿QQ、IOS。~","archived":false,"fork":false,"pushed_at":"2020-01-02T06:03:55.000Z","size":5660,"stargazers_count":3747,"open_issues_count":52,"forks_count":640,"subscribers_count":59,"default_branch":"master","last_synced_at":"2025-04-14T08:14:12.817Z","etag":null,"topics":["listview","recyclerview","sideslip-menu","slide","viewgroup"],"latest_commit_sha":null,"homepage":"http://blog.csdn.net/zxt0601/article/details/52303781","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mcxtzhang.png","metadata":{"files":{"readme":"README-cn.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-25T08:10:45.000Z","updated_at":"2025-04-14T01:36:42.000Z","dependencies_parsed_at":"2022-07-13T19:10:26.918Z","dependency_job_id":null,"html_url":"https://github.com/mcxtzhang/SwipeDelMenuLayout","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcxtzhang%2FSwipeDelMenuLayout","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcxtzhang%2FSwipeDelMenuLayout/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcxtzhang%2FSwipeDelMenuLayout/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcxtzhang%2FSwipeDelMenuLayout/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mcxtzhang","download_url":"https://codeload.github.com/mcxtzhang/SwipeDelMenuLayout/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249926394,"owners_count":21346546,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["listview","recyclerview","sideslip-menu","slide","viewgroup"],"created_at":"2024-08-02T01:01:31.711Z","updated_at":"2025-04-20T16:32:23.256Z","avatar_url":"https://github.com/mcxtzhang.png","language":"Java","readme":"# SwipeDelMenuLayout\n[![](https://jitpack.io/v/mcxtzhang/SwipeDelMenuLayout.svg)](https://jitpack.io/#mcxtzhang/SwipeDelMenuLayout)\n\n相关博文：\n从0实现V1.0版本\nhttp://blog.csdn.net/zxt0601/article/details/52303781 \n\nV1.2版本的更新和改动以及使用\nhttp://blog.csdn.net/zxt0601/article/details/53157090\n\n喜欢随手点个star 多谢 \n##  在哪里找到我：\n我的github：\n\nhttps://github.com/mcxtzhang\n\n我的CSDN博客：\n\nhttp://blog.csdn.net/zxt0601\n\n我的稀土掘金：\n\nhttp://gold.xitu.io/user/56de210b816dfa0052e66495\n\n我的简书：\n\nhttp://www.jianshu.com/users/8e91ff99b072/timeline\n\n***\n# 重要的话 开头说，not for the RecyclerView or ListView, for the Any ViewGroup.\n本控件**不依赖任何**父布局，不是针对 RecyclerView、ListView，而是**任意的ViewGroup**里的childView都可以使用侧滑(删除)菜单。\n\n# 概述\n\n本控件从撸出来在项目使用至今已经过去7个月，距离第一次将它push至github上，也已经2月+。（之前，我发表过一篇文章。传送门:http://gold.xitu.io/entry/57d1115dbf22ec005f9593c6/detail, 里面详细描述了本控件V1.0版本是怎么实现的。）\n\n\n期间有很多朋友在评论、issue里提出了一些**改进**意见，例如支持设置滑动方向（左右）、高仿QQ的交互、支持GridLayoutManager等，以及一些**bug**。已经被我**全部实、修复**。并且将其打包至jitpack，引入**更方便**。和第一版相比，改动挺多的。故将其整理，新发一版。\n\n那么本文先从如何使用它讲起，然后介绍它包含的特性、支持的属性。最后就几个难点和冲突的解决进行讲解。\n\n代码传送门：喜欢的话，随手点个star。多谢\nhttps://github.com/mcxtzhang/SwipeDelMenuLayout\n\n先上几个gif给各位看官感受一下最新版的魅力（以下版本都顺便展示了可选的双向滑动）\n\n本控件最大魅力就是0耦合,所以先上配合我另一个库组装的效果(ItemDecorationIndexBar + SwipeMenuLayout)：\n(ItemDecorationIndexBar : https://github.com/mcxtzhang/ItemDecorationIndexBar)\n\n![image](https://github.com/mcxtzhang/SwipeDelMenuLayout/blob/master/gif/ItemDecorationIndexBar_SwipeDel.gif)\n\n随便来个流式布局也不在话下：\n\n![](https://github.com/mcxtzhang/SwipeDelMenuLayout/blob/master/gif/FlowSwipe.gif)\n\n\nAndroid Special Version （无阻塞式，侧滑菜单展开时，依然可以展开其他侧滑菜单，同时上一个菜单会自动关闭）:\n\n![image](https://github.com/mcxtzhang/SwipeDelMenuLayout/blob/master/gif/LinearLayoutManager1.gif)\n\nGridLayoutManager （和上图的代码比，只需修改RecyclerView的LayoutManager。）:\n\n![image](https://github.com/mcxtzhang/SwipeDelMenuLayout/blob/master/gif/grid.gif)\n\nLinearLayout （不需任何修改，连LinearLayout也可以简单的实现侧滑菜单）:\n\n![image](https://github.com/mcxtzhang/SwipeDelMenuLayout/blob/master/gif/linear.gif)\n\niOS interaction （阻塞式交互，高仿QQ，侧滑菜单展开式，屏蔽其他ITEM所有操作）:\n\n![image](https://github.com/mcxtzhang/SwipeDelMenuLayout/blob/master/gif/iOS.gif)\n\n在ViewPager中使用：\n![image](https://github.com/mcxtzhang/SwipeDelMenuLayout/blob/master/gif/viewpager.gif)\n\n\n\n\n\n# 使用：\nStep 1. 在项目根build.gradle文件中增加JitPack仓库依赖。\n```\n    allprojects {\n\t\trepositories {\n\t\t\t...\n\t\t\tmaven { url \"https://jitpack.io\" }\n\t\t}\n\t}\n```\nStep 2. Add the dependency\n```\n    dependencies {\n\t        compile 'com.github.mcxtzhang:SwipeDelMenuLayout:V1.3.0'\n\t}\n```\n\n\nStep 3. 在需要侧滑删除的ContentItem外面套上本控件，在本控件内依次排列ContentItem、菜单即可：\n\n**至此 您就可以使用高仿IOS、QQ 侧滑删除菜单功能了**\n（侧滑菜单的点击事件等是通过设置的id取到，与其他控件一致，不再赘述）\n\nDemo里，我的ContentItem是一个TextView，那么我就在其外嵌套本控件，并且以侧滑菜单出现的顺序，依次排列菜单控件即可。\n```\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003ccom.mcxtzhang.swipemenulib.SwipeMenuLayout\n    xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"100dp\"\n    android:clickable=\"true\"\n    android:paddingBottom=\"1dp\"\u003e\n\n    \u003cTextView\n        android:id=\"@+id/content\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"\n        android:background=\"?android:attr/selectableItemBackground\"\n        android:gravity=\"center\"\n        android:text=\"项目中我是任意复杂的原ContentItem布局\"/\u003e\n\n    \u003c!-- 以下都是侧滑菜单的内容依序排列 --\u003e\n    \u003cButton\n        android:id=\"@+id/btnTop\"\n        android:layout_width=\"60dp\"\n        android:layout_height=\"match_parent\"\n        android:background=\"#d9dee4\"\n        android:text=\"置顶\"\n        android:textColor=\"@android:color/white\"/\u003e\n\n    \u003cButton\n        android:id=\"@+id/btnUnRead\"\n        android:layout_width=\"120dp\"\n        android:layout_height=\"match_parent\"\n        android:background=\"#ecd50a\"\n        android:clickable=\"true\"\n        android:text=\"标记未读\"\n        android:textColor=\"@android:color/white\"/\u003e\n\n    \u003cButton\n        android:id=\"@+id/btnDelete\"\n        android:layout_width=\"60dp\"\n        android:layout_height=\"match_parent\"\n        android:background=\"@color/red_ff4a57\"\n        android:text=\"删除\"\n        android:textColor=\"@android:color/white\"/\u003e\n\n\u003c/com.mcxtzhang.swipemenulib.SwipeMenuLayout\u003e\n\n```\n\n**注意事项**：\n* 若是在ListView、RecyclerView中使用，点击事件正确的设置应该是在 Adapter  里对 ContentItem 设置，不能使用listview.setOnItemClickListener。\n因为此时 Item 是本控件了，不是里面的 ContentItem 那块区域了，且本控件区域有很多触摸的判断，内部包含 ContentItem 和侧滑菜单 Menu。\n\n* 在ListView中使用，\n在ListView里，点击侧滑菜单上的选项时，如果想让侧滑菜单同时关闭，\n\n将ItemView强转成CstSwipeDelMenu，并调用quickClose()。\n\n如：\n((CstSwipeDelMenu) holder.getConvertView()).quickClose(); \n\n\n推荐使用RecyclerView， \n\n在RecyclerView中，如果删除时，建议使用mAdapter.notifyItemRemoved(pos)，\n\n否则删除没有动画效果， 且如果想让侧滑菜单同时关闭，也需要同时调用 ((CstSwipeDelMenu) holder.itemView).quickClose();\n\n\n* 在ViewPager中使用：\n用`CstViewPager`替换`ViewPager`，解决滑动冲突\n```\n    \u003ccom.mcxtzhang.swipemenulib.CstViewPager\n        android:id=\"@+id/viewPager\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"\u003e\u003c/com.mcxtzhang.swipemenulib.CstViewPager\u003e\n```\n---\n\n# 支持属性：\n1 通过 isIos 变量控制是否是IOS阻塞式交互，默认是打开的。\n2 通过 isSwipeEnable 变量控制是否开启右滑菜单，默认打开。（某些场景，复用item，没有编辑权限的用户不能右滑）\n3 通过开关 isLeftSwipe支持左滑右滑\n\n有两种方式设置：\n一：xml：\n\n```xml\n\u003ccom.mcxtzhang.swipemenulib.SwipeMenuLayout\n    xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n    app:ios=\"false\"\n    app:leftSwipe=\"true\"\n    app:swipeEnable=\"true\"\u003e\n```\n\n二： java代码：\n```java\n//这句话关掉IOS阻塞式交互效果 并依次打开左滑右滑  禁用掉侧滑菜单\n((SwipeMenuLayout) holder.itemView).setIos(false).setLeftSwipe(position % 2 == 0 ? true : false).setSwipeEnable(false);\n```\n\n# 支持特性：\n\n* 不会同时展开2+个侧滑菜单。（可见界面上最多只会出现一个侧滑菜单）。\n* 侧滑过程中，禁止父控件上下滑动。\n* 多指同时滑动，屏蔽后触摸的几根手指。\n* 增加viewChache 的 get()方法，可以用在：当点击外部空白处时，关闭正在展开的侧滑菜单。\n* 以第一个子Item(即ContentItem)的宽度为控件宽度\n\n\n# 每次更新的checklist：\n由于持续迭代，会发生完成一个feature、fix一个bug后，导致新的bug。\nso，整理一份checkList，供每次迭代后验证，都通过，才会push到github库上。\n\n项目 | 备注 | 验证\n--- |----------| ---\nisIos | 切换至IOS阻塞交互模式、Android特色无阻塞交互模式 以下feature都可正常工作|\nisSwipeEnable | 是否支持关闭侧滑功能\nisLeftSwipe | 是否支持双向滑动\nContentItem内容可单击 | \nContentItem内容可长按 |\n侧滑菜单显示时，ContentItem不可点击 |\n侧滑菜单显示时，ContentItem不可长按 |\n侧滑菜单显示时，侧滑菜单可以点击 |\n侧滑菜单显示时，点击ContentItem区域关闭菜单 |\n侧滑过程中，屏蔽长按事件 |\n通过滑动关闭菜单，不应该触发ContentItem点击事件 |\n\n\n---\n\n###更新日志###\n2017 09 27更新：\n* 解决 滑动冲突的 ViewPager：CstViewPager\n因为ViewPager 和 SwipMenuLayout都是水平方向滑动的控件。所以在一起使用时会有冲突，使用CstViewPager，可以在ViewPager的第一页使用左滑。在ViewPager的最后一页使用右滑菜单。\n\n2016 12 09更新：\n* ListView快速滑动快速删除时，偶现菜单不消失的bug。\n\n2016 12 07 更新：\n * 禁止侧滑时(isSwipeEnable false)，点击事件不受干扰。\n \n2016 11 14 更新：\n * 支持padding,且后续计划加入上滑下滑，因此不再支持ContentItem的margin属性。\n * 修改回弹的动画，更平滑。\n * 微小位移的move不回回弹的bug\n\n2016 11 09 更新：\n1 适配GridLayoutManager，将以第一个子Item(即ContentItem)的宽度为控件宽度。\n2 使用时，如果需要撑满布局，切记第一个子Item(Content)，宽度要是match_parent.\n\n2016 11 04 更新：\n1 优化了长按事件和侧滑事件的关系，尽量的参考QQ。\n\n2016 11 03 更新：\n1 判断手指起始落点，如果距离属于滑动了，就屏蔽一切点击事件（和QQ交互一样）\n\n2016 10 21 更新：\n1 当父控件宽度不是全屏时的bug。\n2 仿QQ，侧滑菜单展开时，点击除侧滑菜单之外的所有区域包括菜单的内容部分，关闭侧滑菜单。\n\n2016 10 21 更新：\n1 增加viewChache 的 get()方法，可以用在：当点击外部空白处时，关闭正在展开的侧滑菜单。\n\n2016 09 30 更新：\n1 支持多向滑动：\n![image](https://github.com/mcxtzhang/SwipeDelMenuLayout/blob/master/gif/doubleSwipe.gif)\n\n2016 09 28 更新点：\n1 增加一个item点击事件设置的示例。\n\n2016 09 12 更新点：\n1 增加用RecyclerView、ListView实现的完整删除Demo 供不会用的同学参考。\n2 增加一个quickClose()方法，更好的在ListView中使用，不过还是推荐大家用RecyclerView。\n\n\n\n---\n","funding_links":[],"categories":["滑动删除"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcxtzhang%2FSwipeDelMenuLayout","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcxtzhang%2FSwipeDelMenuLayout","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcxtzhang%2FSwipeDelMenuLayout/lists"}