简体   繁体   English

Android中的ViewPager滚动问题

[英]ViewPager scrolling issue in Android

I have a ViewPager with dynamic number of images in it. 我有一个ViewPager其中包含动态数量的images This ViewPager is added as a custom row to a table view. ViewPager作为自定义行添加到表视图中。 As this table view can have multiple dynamic custom rows, I have to add this table view in a scrollview for scrolling. 由于此表视图可以有多个自定义动态行,我一定要在添加此表视图scrollview滚动。

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. 现在我的问题是,当我水平滚动到View Pager时,它不是完全水平滚动,它也与一些垂直滚动混合在一起。 So when a vertical scrolling is detected the events are passed to the scroll view; 因此,当检测到垂直滚动时,事件被传递到滚动视图; which makes the ViewPager reset to the initial position. 这使ViewPager重置为初始位置。

So how can I pass back the events to ViewPager or avoid scrollview catching vertical scroll events? 那么如何将事件传递回ViewPager或避免scrollview捕获垂直滚动事件?

Note: I tried disabling scrollview to vertical scrolling but that didn't stop it from capturing the vertical scroll events. 注意:我尝试禁用scrollview到垂直滚动,但这并没有阻止它捕获垂直滚动事件。

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 我通过以下方式为我的Viewpager骑上了触摸事件

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. 注意:myScrollView是myViewPager的父级,如我的问题中所述。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM