预习
如何使用
- 这些行添加到您的
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正常效果
资源均来自第三方,谨慎下载,前往第三方网站下载