ViewPager scrolling issue in Android

坚强是说给别人听的谎言 提交于 2020-01-02 09:37:05

问题


I have a ViewPager with dynamic number of images in it. This ViewPager is added as a custom row to a table view. As this table view can have multiple dynamic custom rows, I have to add this table view in a scrollview for scrolling.

Now my question is, when I am scrolling horizontally to View Pager, it's not exactly horizontal scrolling, it's mixed with some vertical scrolling as well. So when a vertical scrolling is detected the events are passed to the scroll view; which makes the ViewPager reset to the initial position.

So how can I pass back the events to ViewPager or avoid scrollview catching vertical scroll events?

Note: I tried disabling scrollview to vertical scrolling but that didn't stop it from capturing the vertical scroll events.


回答1:


I found the solution for my question and this is how I did it.

I over ride the on touch event for my Viewpager in the following way

myViewPager.setOnTouchListener(new OnTouchListener() {

                public boolean onTouch(View v, MotionEvent event) {

                    if(event.getAction() == MotionEvent.ACTION_MOVE && myScrollView!=null){
                        myScrollView.requestDisallowInterceptTouchEvent(true);
                    }
                    return false;
                }
            });

Note: myScrollView is parent of myViewPager, as said in my question.



来源:https://stackoverflow.com/questions/12322433/viewpager-scrolling-issue-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!