我有ViewGroup实现,但它作为组件而不是容器。好的,当用户滚动控件时,它应该向不同方向滚动 所有 其子项。
所以交互方案是:
|| MotionEvent
\/
My Control
/|\
/ | \
/ | \ message clones
/ | \
Child1 Ch2 Child3
我该如何实施该计划?
未加工变体:
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
boolean intercepted = false;
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
if (child instanceof ViewGroup ) {
intercepted |= ((ViewGroup) child).onInterceptTouchEvent(ev);
}
}
return super.onInterceptTouchEvent(ev) || intercepted;
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
boolean intercepted = false;
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
intercepted |= child.onTouchEvent(ev);
}
return super.onTouchEvent(ev) || intercepted;
}
该变体也不起作用:
private void dispatchTouch(MotionEvent ev) {
for(int i = 0; i < getChildCount(); i++){
getChildAt(i).dispatchTouchEvent(ev);
}
}
我该怎么办?