我试着在StackView里面做可触摸的ScrollView。最后,我CustomStackView扩展StackView并覆盖dispatchTouchEvent了我在父级中不允许触摸事件的位置(即ScrollView)。
public class CustomStackView extends StackView {
public CustomStackView(Context context) {
super(context);
}
public CustomStackView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomStackView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
int action = ev.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
this.getParent().requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_UP:
this.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
super.dispatchTouchEvent(ev);
return true;
}
}
它有效,但有点骇人听闻。你有别的想法吗?