今天要介绍的这个库叫做 SwipeDelMenuLayout
1 史上最简单侧滑菜单,0耦合,支持任意ViewGroup
2 一步集成侧滑(删除)菜单,高仿QQ、IOS
首先看下效果
使用方法如下:
1 导入依赖库
allprojects {
repositories {
....
maven { url "https://jitpack.io" } //根目录build.gradle
}
}
dependencies {
...
compile 'com.github.mcxtzhang:SwipeDelMenuLayout:V1.2.5'//目前最新版本是1.2.5,主项目目录build.gradle
}
2 布局引用
因为一般删除都是侧滑Item,所以需要找到你的item布局文件,举例:
<?xml version="1.0" encoding="utf-8"?>
<!--注意根布局是SwipeMenuLayout -->
<com.mcxtzhang.swipemenulib.SwipeMenuLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="50dp">
<ImageView
android:id="@+id/icon_in"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"/>
<TextView
android:id="@+id/text_in"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我是艾克"
android:gravity="center"
android:textSize="15sp"/>
</LinearLayout>
<!--上面是你的item原本的内容-->
<!--下面是你侧滑之后要显示的内容,比如置顶,标记未读,删除等等-->
<Button
android:id="@+id/btnDelete"
android:layout_width="80dp"
android:layout_height="50dp"
android:background="#ff0000"
android:text="删除"
android:textColor="@android:color/white"/>
</com.mcxtzhang.swipemenulib.SwipeMenuLayout>
剩下的就是写你的删除按钮的逻辑了,这个很简单,就不赘述啦,希望大家喜欢这个库~