Capture OnTouchMove event in ScrollView, scrollviewtouch

Source: Internet
Author: User

Capture OnTouchMove event in ScrollView, scrollviewtouch

ScrollView in Android captures the OnTouch move event and does not pass it to the child control.

We recommend that you use

Scrollview. requestDisallowInterceptTouchEvent (true );

 

However, I did not respond after using it.

So I wrote it like this.

scrollView.setOnTouchListener(new View.OnTouchListener() {            @Override            public boolean onTouch(View v, MotionEvent event) {                linearLayout.dispatchTouchEvent(event);                return false;            }        });

In this way, the scrollview can be passed to the subcontrol linearlayout, but the problem is that the subcontrol of linearlayout

The MOVE event has not been obtained. Currently, I do not know how to solve it.


A ScrollView is added to the view. How does one respond to the touch event?

UIScrollView itself cannot handle touch events. To achieve this, you must perform touch processing on the subView on UIScrollView in a simple way. For example, to respond to the UIImageView on scrollView, create a subclass of UIImageVIew, the custom UIImageView handles the touch event header file declaration as follows: # import @ protocol ImageTouchDelegate-(void) imageTouch :( NSSet *) touches withEvent :( UIEvent *) event whichView :( id) imageView; @ end @ interface ImageTouchView: UIImageView {id delegate; BOOL delegatrue;} @ property (nonatomic, assign) id delegate; @ end this is the header file, the source file can be like this @ implementation ImageTouchView @ synthesize delegate;-(id) initWithFrame :( CGRect) frame {if (self = [super initWithFrame: frame]) {[self setUserInteractionEnabled: YES]; delegatrue = YES;} return self;}-(BOOL) touchesShouldBegin :( NSSet *) touches withEvent :( UIEvent *) event inContentView :( UIView *) view {return YES ;} -(void) touchesBegan :( NSSet *) touches withEvent :( UIEvent *) event {if (delegatrue) {[delegate imageTouch: touches withEvent: event whichView: self];}

How can we avoid triggering Touch events of internal components during ScrollView scrolling?

You can use onInterceptTouchEvent to intercept the event...
 

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.