【发布时间】:2015-11-24 13:53:12
【问题描述】:
我有一个父 recyclerview,里面装满了卡片,每张卡片里面都有一个内部 recyclerview。
卡片内的内部回收视图的滚动已被禁用,但这也影响了内部回收视图接收点击事件的能力。
为了禁用滚动,我在这里采用了与 Lucas Crawford 的回答非常相似的方法,该方法建议您创建一个自定义 recyclerview 类并覆盖 dispatchTouchEvent:Disable Scrolling in child Recyclerview android
我的班级是这样的:
public class ScrollThroughRecyclerView extends RecyclerView {
private boolean isOnClick;
public ScrollThroughRecyclerView(Context context) {
super(context);
}
public ScrollThroughRecyclerView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ScrollThroughRecyclerView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
final int action = ev.getAction();
final int actionMasked = action & MotionEvent.ACTION_MASK;
Log.e("actionmasked", "" + actionMasked);
switch (actionMasked) {
case MotionEvent.ACTION_DOWN:
Log.e("motionDown", "onclick: "+isOnClick);
isOnClick = true;
break;
case MotionEvent.ACTION_MOVE:
isOnClick = false;
Log.e("motionMove", "onclick: "+isOnClick);
return true;
case MotionEvent.ACTION_UP:
Log.e("motionUp", "onclick: "+isOnClick);
if (isOnClick) {
return super.dispatchTouchEvent(ev);
}
break;
default:
return true;
}
return true;
}
但是,它从不注册点击事件,但滚动被正确禁用。
如何让内部recyclerview注册点击事件?
【问题讨论】:
-
ExpandableListView可能会更好
标签: android android-recyclerview motionevent