SwipeDelMenuLayout
- https://github.com/mcxtzhang/SwipeDelMenuLayout
- 菜单 (Menu)
- ★★★★★
- 2016-11-18 10:34
- 3536 kb
- Android Studio
- 2440 次
- 293 次
介绍:
运行效果:

使用说明:
本控件不依赖任何父布局,不是针对 RecyclerView、ListView,而是任意的ViewGroup里的childView都可以使用侧滑(删除)菜单。
Step 1. 在项目根build.gradle文件中增加JitPack仓库依赖。
- allprojects {
- repositories {
- ...
- maven { url "https://jitpack.io" }
- }
- }
Step 2. Add the dependency
- dependencies {
- compile 'com.github.mcxtzhang:SwipeDelMenuLayout:V1.2.2'
- }
Step 3. 在需要侧滑删除的ContentItem外面套上本控件,在本控件内依次排列ContentItem、菜单即可:
至此 您就可以使用高仿IOS、QQ 侧滑删除菜单功能了 (侧滑菜单的点击事件等是通过设置的id取到,与其他控件一致,不再赘述)
Demo里,我的ContentItem是一个TextView,那么我就在其外嵌套本控件,并且以侧滑菜单出现的顺序,依次排列菜单控件即可。
- <?xml version="1.0" encoding="utf-8"?>
- <com.mcxtzhang.swipemenulib.SwipeMenuLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="100dp"
- android:clickable="true"
- android:paddingBottom="1dp">
- <TextView
- android:id="@+id/content"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="?android:attr/selectableItemBackground"
- android:gravity="center"
- android:text="项目中我是任意复杂的原ContentItem布局"/>
- <!-- 以下都是侧滑菜单的内容依序排列 -->
- <Button
- android:id="@+id/btnTop"
- android:layout_width="60dp"
- android:layout_height="match_parent"
- android:background="#d9dee4"
- android:text="置顶"
- android:textColor="@android:color/white"/>
- <Button
- android:id="@+id/btnUnRead"
- android:layout_width="120dp"
- android:layout_height="match_parent"
- android:background="#ecd50a"
- android:clickable="true"
- android:text="标记未读"
- android:textColor="@android:color/white"/>
- <Button
- android:id="@+id/btnDelete"
- android:layout_width="60dp"
- android:layout_height="match_parent"
- android:background="@color/red_ff4a57"
- android:text="删除"
- android:textColor="@android:color/white"/>
- </com.mcxtzhang.swipemenulib.SwipeMenuLayout>
唯一注意事项: 若是在ListView、RecyclerView中使用,点击事件正确的设置应该是在 Adapter 里对 ContentItem 设置,不能使用listview.setOnItemClickListener。 因为此时 Item 是本控件了,不是里面的 ContentItem 那块区域了,且本控件区域有很多触摸的判断,内部包含 ContentItem 和侧滑菜单 Menu。
支持属性:
1 通过 isIos 变量控制是否是IOS阻塞式交互,默认是打开的。 2 通过 isSwipeEnable 变量控制是否开启右滑菜单,默认打开。(某些场景,复用item,没有编辑权限的用户不能右滑) 3 通过开关 isLeftSwipe支持左滑右滑
有两种方式设置: 一:xml:
- <com.mcxtzhang.swipemenulib.SwipeMenuLayout
- xmlns:app="http://schemas.android.com/apk/res-auto"
- app:ios="false"
- app:leftSwipe="true"
- app:swipeEnable="true">
二: java代码:
//这句话关掉IOS阻塞式交互效果 并依次打开左滑右滑 禁用掉侧滑菜单
- ((SwipeMenuLayout) holder.itemView).setIos(false).setLeftSwipe(position % 2 == 0 ? true : false).setSwipeEnable(false);
支持特性:
不会同时展开2+个侧滑菜单。(可见界面上最多只会出现一个侧滑菜单)。
侧滑过程中,禁止父控件上下滑动。
多指同时滑动,屏蔽后触摸的几根手指。
增加viewChache 的 get()方法,可以用在:当点击外部空白处时,关闭正在展开的侧滑菜单。
以第一个子Item(即ContentItem)的宽度为控件宽度
浙公网安备 33010602011771号