requestDisallowInterceptTouchEvent does not work unless selecting view first

前端 未结 2 1654

According to android docs you can get your parent ViewGroup and call requestDisallowInterceptTouchEvent(true) on it to stop other things from interferi

2条回答
  •  日久生厌
    2021-02-04 12:17

    I had some problems too with 2.3 where it the disallow would intermittenltly work.

    I used to call view.requestDisallowInterceptTouchEvent(true) regardless of the event.getAction().

    Then I tried to be a good citizen and changed my code in the onTouch() method to the following:

    switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                v.requestDisallowInterceptTouchEvent(true);
                break;
            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_UP:
                v.requestDisallowInterceptTouchEvent(false);
                break;
            default:
                break;
            }
    

    Remember that this method (or some other views under the referenced view) has to return true for the parents to adhere to the disallow request.

    Not sure this will fix your issue but worth a try.

提交回复
热议问题