Horizontal Scroll View inside ViewPager

后端 未结 3 1124
忘了有多久
忘了有多久 2020-12-13 22:59

I have horizontal scrolling pages as in the android market (ViewPager).

My problem is that i want to have a Horizontal Scrolling View in them with some images?Is tha

3条回答
  •  心在旅途
    2020-12-13 23:30

    You need to extend the HorizontalScrollView and intercept touch events. What worked for me was the following sample:

    public class MyScrollView extends HorizontalScrollView {
    
        public MyScrollView(Context p_context, AttributeSet p_attrs)
        {
            super(p_context, p_attrs);
        }
    
        @Override
        public boolean onInterceptTouchEvent(MotionEvent p_event)
        {
            return true;
        }
    
        @Override
        public boolean onTouchEvent(MotionEvent p_event)
        {
            if (p_event.getAction() == MotionEvent.ACTION_MOVE && getParent() != null)
            {
                getParent().requestDisallowInterceptTouchEvent(true);
            }
    
            return super.onTouchEvent(p_event);
        }
    }
    

    Then, instead of using the HorizontalScrollView in your layout XML, you need to use this custom view.

    What helped me get to this solution is this post

提交回复
热议问题