How Android blocks Seekbar Touch events

Source: Internet
Author: User

We all know that Android is Seekbar, when your finger is sliding on the Seekbar, Seekbar's progress bar will always go with your finger, but in some cases you may find it tricky to disable Seekbar.

In fact, we see the Seekbar class itself does not rewrite the Ontouchevent event, then continue to find its parent class Absseekbar, we see Ontouchevent is rewritten in Absseekbar, write the content we do not care about, We know that Ontouchevent was distributed in dispatchtouchevent, and we looked directly at the dispatchtouchevent of the view:

    PublicBoolean dispatchtouchevent (motioneventEvent) {        if(Minputeventconsistencyverifier! =NULL) {minputeventconsistencyverifier.ontouchevent (Event,0); }        if(Onfiltertoucheventforsecurity (Event)) {            //noinspection simplifiableifstatementListenerinfo Li =Mlistenerinfo; if(Li! =NULL&&Li.montouchlistener! = null && (Mviewflags & enabled_mask) = =ENABLED&&Li.mOnTouchListener.onTouch (This, event )) {                return true; }            if(Ontouchevent (Event)) {                return true; }        }        if(Minputeventconsistencyverifier! =NULL) {minputeventconsistencyverifier.onunhandledevent (Event,0); }        return false; }

We look at the fact that as long as li.montouchlistener! = null&& Li.mOnTouchListener.onTouch (this, the event) This judgment is established, Indicates that the Outouch event has been digested by this component, no longer distributed, the judgment is not established, will continue to judge if (Ontouchevent (event)) this sentence.

Then we recall Seekbar touch process, when you touch the Seekbar, Seekbar go first to call Inherit view Dispatchtouchevent .... And what if we don't want to make the Seekbar itself ontouchevent?

Of course, it's bound to seekbar a ontouchlistener and returns true.

If you want the touchevent of Seekbar itself to be set up, bind a ontouchlistener to Seekbar and return false to Meow

>_<

How Android blocks Seekbar Touch events

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.