Android StackView inside ScrollView

118 views Asked by At

I try to make StackView touchtable inside ScrollView. Finnaly I make CustomStackView which extends StackView and override dispatchTouchEvent where I disallow touch event in parent (which is 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;
}
}

It works but is a little bit hackish. Have you got any other idea?

0

There are 0 answers