ScrollView Nested ListView (ViewGroup event distribution) __scrollview

Source: Internet
Author: User
ScrollView Nested ListView Event Distribution problem (disallowintercept in hidden)#转载请注明出处, thank you. A few days ago friends asked ScrollView nested listview, sliding events only in the Scrollview,listview internal can not slide, although he found a solution, but the reason is still foggy, know it, I do not know why. I'm here with friends who want to know what's going on, to find out how to solve the problem of this type of event distribution, my blog or the idea of the subject (here provide two solutions), will slightly interpret the source code, first of all: before the problem solved, sliding listview, the internal Item no movement, But the whole scrollview rolling, nature is not what we want.
After the problem is solved, the slide listview, the internal item scrolls up and down, the sliding listview outside the part, the whole scrollview scrolling, perfect.
From the point of view of the phenomenon, obviously is ListView move event was intercepted by ScrollView, in fact, experienced friends should find that the general event distribution of the conflict is for move, rarely need to resolve the click of the conflict of the bar (if there is, you are still a rookie, a joke.) )。 Think of interception, we are not in the mind, yes, rewrite the "Onintercepttouchevent" method, return False, so that ScrollView cannot intercept events, so the problem is not solved, then the first solution came out: scenario I, rewrite the Onintercepttouchevent method:
@Override Public
    Boolean onintercepttouchevent (motionevent ev) {return
        false;
    }
Then you may ask, why do not intercept the event, move event to intercept it. This is the difference between the leadership and subordinates, you want to ah, do things must be given to the following people do AH (so with the distribution of events, most of the matter to subordinate subordinates ...) Dry), if you want to work, you say is not the first to go, a better leader may have gone, but also tell the following people can also work (this is the first solution, met good leadership, he rewrote the onintercepttouchevent, the default does not intercept, All message sharing) Bad leaders sure want to let you work overtime, more to bring him income ah, so he walked without saying let you go, continue to work overtime Bai ... Now let's take a look at the "dispatchtouchevent" Source:
From the source point of view, the second solution is to start from the disallowintercept, this variable from the literal meaning is "not allowed to intercept", this can have ah, then there is not allowed to set up a method of interception, there are really " Requestdisallowintercepttouchevent (True). Hope to come, leaders let us work overtime, do not let us move, we can not apply for overtime. Then where to apply, down when you do not worry, the leadership will not intercept, for fear you do not, naturally in move time, this time there is a second solution: Scheme II, applications are not intercepted: (can also be applied in the ListView Ontouch event, so that you do not need to customize the ScrollView, set the object is ScrollView)
@Override Public
    Boolean dispatchtouchevent (motionevent ev) {
        //Disable blocking touch events (allow pass down)
//		Requestdisallowintercepttouchevent (true);
        Switch (ev.getaction ()) {case
            motionevent.action_down: Break
                ;
            Case Motionevent.action_move:
                //prohibit interception of touch events (allow to pass down)
		requestdisallowintercepttouchevent (true);
                break;
            Case MOTIONEVENT.ACTION_UP:
                log.e ("Up", "dispatch" + sum);
            Case Motionevent.action_cancel:
                //Release-prohibit interception of touch event
		Requestdisallowintercepttouchevent (false);
                break;

            Default: Break
                ;
        }
        return super.dispatchtouchevent (EV);
    }
Finally, we give you an event flow chart to facilitate better understanding and absorption:

This is based on the source code to draw the flow chart, the event came in there are two major checkpoints can intercept, the first checkpoint is Disallowintercept, the second is onintercept, as long as the setting of any one can let the view of the following smoothly get the desired event, Talk about here basically will come to an ending, welcome everybody to visit my other blog ... The source code is simpler, does not recommend downloading, certainly also provides the download, here only provides the CSDN download: http://download.csdn.net/detail/aiyh0202/9659839

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.