ScrollView中的Android StackView

时间:2016-12-20 12:29:19

标签: android scrollview stackview

我尝试在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。你还有其他想法吗?

0 个答案:

没有答案
相关问题