Solve the sliding conflict problem of scrollview nested viewpager

Source: Internet
Author: User

Simple. You only need to override scrollview.



Import android. content. context; import android. util. attributeset; import android. view. gesturedetector; import android. view. gesturedetector. simpleongesturelistener; import android. view. motionevent; import android. view. view; import android. widget. scrollview;/** rewrite scrollview * to solve the sliding conflict problem of scrollview nested viewpager * @ date 11:04:22 * @ author zhangyi **/public class myscrollview extends scrollview {private Boolean canscroll; private gesturedetector mgesturedetector; view. ontouchlistener mgesturelistener; Public myscrollview (context, attributeset attrs) {super (context, attrs); mgesturedetector = new gesturedetector (New Role (); canscroll = true ;} @ override public Boolean onintercepttouchevent (motionevent eV) {If (ev. getaction () = motionevent. action_up) canscroll = true; return Super. onintercepttouchevent (EV) & mgesturedetector. ontouchevent (EV);} class extends simpleongesturelistener {@ override public Boolean onscroll (motionevent E1, motionevent E2, float distancex, float distancey) {If (canscroll) if (math. ABS (distancey)> = math. ABS (distancex) canscroll = true; else canscroll = false; return canscroll ;}}}


Use XML to call the custom scrollview Method


Replace the original scrollview component name with the package name. myscrollview.


<com.zy.myview.ScrollView          android:layout_width="fill_parent"android:layout_height="wrap_content" android:scrollbars="none"        >          <LinearLayout            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:layout_gravity="top"            android:orientation="vertical" >
........


If you encounter the same problem, try it.

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.