我尝试在StackView
内设置ScrollView
触摸屏。 Finnaly我使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;
}
}
它有效,但有点hackish。你还有其他想法吗?