Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDFView in a ScrollView #51

Open
JeanChristophePal opened this issue Jul 29, 2016 · 2 comments
Open

PDFView in a ScrollView #51

JeanChristophePal opened this issue Jul 29, 2016 · 2 comments

Comments

@JeanChristophePal
Copy link

Hello,

I need to put the PDFView in a ScrollView, how should I do it?

So far, either the PDFView is not showing or the scroll is not working.

Thank you

@JeanChristophePal
Copy link
Author

The problem is mainly due to the ScrollView behavior. To swipe horizontally a PDFView, which is in a Vertical Scrollview, motion has to be rigorously horizontal, if its a little UP or DOWN the swipe is stopped...

The hack found on internet is to test the motion distance (more vertically than horizontally?):

public class EnableLateralMotionScrollView extends ScrollView {

    private GestureDetector mGestureDetector;

    public EnableLateralMotionScrollView(Context context, AttributeSet attrs  ) {
        super(context, attrs);
        mGestureDetector = new GestureDetector(context, new YScrollDetector());
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev);
    }

    // Return false if we're scrolling in the x direction
    class YScrollDetector extends GestureDetector.SimpleOnGestureListener {
        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
            return Math.abs(distanceY) > Math.abs(distanceX);
        }
    }

}

This is not perfect but it worked.

Do you have a better solution?

@rickyngan
Copy link

rickyngan commented Aug 27, 2017

I find this another workable solution using ScrollView subclass (my case is in minSDKVersion API 16)

public class NoInterceptScrollView extends ScrollView {

    public NoInterceptScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return false;
    }
}

refer: https://stackoverflow.com/questions/17671123/scrollview-inside-a-scrollview-in-android-issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants