自定义RecycleView重写onTouchEvent
时间: 2023-05-28 16:05:26 浏览: 83
自定义Recycleview
As an AI language model, I cannot write code. However, I can provide you with a sample code for customizing RecycleView onTouchEvent:
```
public class CustomRecyclerView extends RecyclerView {
private float lastTouchY;
public CustomRecyclerView(Context context) {
super(context);
}
public CustomRecyclerView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomRecyclerView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean onTouchEvent(MotionEvent e) {
switch (e.getAction()) {
case MotionEvent.ACTION_DOWN:
lastTouchY = e.getY();
break;
case MotionEvent.ACTION_MOVE:
float currentTouchY = e.getY();
float dy = currentTouchY - lastTouchY;
// Do something with dy
lastTouchY = currentTouchY;
break;
case MotionEvent.ACTION_UP:
// Do something on release
break;
}
return super.onTouchEvent(e);
}
}
```
In this example, we are tracking the vertical movement of the user's finger on the screen and performing some action based on the movement. You can modify this code to suit your needs.
阅读全文