Skip to content

Commit e22a4f9

Browse files
author
zhangxutong
committed
添加探探Demo:Callback中增加一个isLeftSwipe变量,表示左滑还是右滑
1 parent e7c6f46 commit e22a4f9

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

app/src/main/java/com/mcxtzhang/flowlayoutmanager/tantan/TanTanCallback.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.util.Log;
66
import android.util.TypedValue;
77
import android.view.View;
8+
import android.widget.Toast;
89

910
import com.mcxtzhang.commonadapter.rv.ViewHolder;
1011
import com.mcxtzhang.flowlayoutmanager.R;
@@ -103,10 +104,18 @@ public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
103104
//如果不需要循环删除
104105
/* Object remove = mDatas.remove(viewHolder.getLayoutPosition());
105106
mAdapter.notifyDataSetChanged();*/
107+
Log.e("swipecard", "厉害了");
108+
109+
if (isLeftSwipe){
110+
Toast.makeText(mRv.getContext(), "左滑删除", Toast.LENGTH_SHORT).show();
111+
}else {
112+
Toast.makeText(mRv.getContext(), "右滑删除", Toast.LENGTH_SHORT).show();
113+
}
106114

107115
//探探只是第一层加了rotate & alpha的操作
108116
//对rotate进行复位
109117
viewHolder.itemView.setRotation(0);
118+
110119
//自己感受一下吧 Alpha
111120
if (viewHolder instanceof ViewHolder) {
112121
ViewHolder holder = (ViewHolder) viewHolder;
@@ -169,5 +178,17 @@ public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHo
169178
}
170179
}
171180
}
181+
182+
183+
//可以在此判断左右滑:
184+
float v = mRv.getWidth() / 2 - viewHolder.itemView.getX() - (viewHolder.itemView.getWidth() / 2);
185+
if (v > 0) {
186+
isLeftSwipe = true;
187+
} else if (v < 0) {
188+
isLeftSwipe = false;
189+
}
172190
}
191+
192+
//一个flag 判断左右滑
193+
private boolean isLeftSwipe;
173194
}

0 commit comments

Comments
 (0)