build.gradle
repositories {
maven {
url "https://jitpack.io"
}
}
dependencies {
compile 'com.github.CodeFalling:RecyclerViewSwipeDismiss:v1.1.3'
}
onTouchListener
并绑定到你的RecyclerView
SwipeDismissRecyclerViewTouchListener listener = new SwipeDismissRecyclerViewTouchListener.Builder(
recyclerView,
new SwipeDismissRecyclerViewTouchListener.DismissCallbacks() {
@Override
public boolean canDismiss(int position) {
return true;
}
@Override
public void onDismiss(View view) {
// Do what you want when dismiss
}
})
.setIsVertical(false)
.setItemTouchCallback(
new SwipeDismissRecyclerViewTouchListener.OnItemTouchCallBack() {
@Override
public void onTouch(int index) {
// Do what you want when item be touched
}
})
.setItemClickCallback(new SwipeDismissRecyclerViewTouchListener.OnItemClickCallBack() {
@Override
public void onClick(int position) {
// Do what you want when item be clicked }
})
.setBackgroundId(R.drawable.bg_item_normal, R.drawable.bg_item_selected)
.create();
recyclerView.setOnTouchListener(listener);
setIsVertical(false)
是指允许在水平方向轻扫
listener.setEnabled(false)
可以禁用滑动将其关闭
onTouch
将被调用时MOUSE_UP上项目不刷卡
onClick
将被调用时ACTION_UP上项目1秒内移动超过固定距离没有更多
通过使用setBackgroundId
,您可以设置背景ID为项目的正常和按下的状态,就像在RecyclerView正常效果
热门源码