ViewPager nested in ViewPager

后端 未结 3 1039
离开以前
离开以前 2020-12-25 09:47

I\'m really newbie in android and I would appreciate any help for my course work.

I need to do:

1) two ViewPagers (not nested) in one Activity

2) two

3条回答
  •  一个人的身影
    2020-12-25 10:33

    A solution about having a nested Viewpager and disabling the nested Viewpager swiping (if you want to set the selected pages with buttons in the nested)

    For the nested You SubClass ViewPager and you add these:

     public boolean onInterceptTouchEvent(MotionEvent event) {
            //if you want to send the Touches to this Viewpager (the nested) //change true to false
          return true;    
        }
    
        @Override
        public boolean onTouchEvent(MotionEvent event) {
            // Never allow swiping to switch between pages on this inner 
    
            //send swipe to father instead of child
            if (this.getParent()!=null &&  this.getParent() instanceof ViewPager) {
                ((ViewPager) this.getParent()).onTouchEvent(event);
            }
            return false;
        }
    

    In the Layouts you put this:

    
    

提交回复
热议问题