Foggy day
Android - Viewpager2 inside Viewpager2 본문
when there is Viewpager2 inside Viewpager2, ViewPager2 inside can't be swiped.
You can see explanation of it in Google Doc.
developer.android.com/training/animation/vp2-migration#nested-scrollables
Support nested scrollable elements
ViewPager2 does not natively support nested scroll views in cases where the scroll view has the same orientation as the ViewPager2 object that contains it. For example, scrolling would not work for a vertical scroll view inside a vertically-oriented ViewPager2 object.
To support a scroll view inside a ViewPager2 object with the same orientation, you must call requestDisallowInterceptTouchEvent(). on the ViewPager2 object when you expect to scroll the nested element instead. The ViewPager2 nested scrolling sample demonstrates one way of solving this problem with a versatile custom wrappger layout.
In this case, the solution is to call requestDisallowInterceptTouchEvent(true) in setOnTouchListener of child viewpager2.
childViewPager2.setOnTouchListener((view, motionEvent) -> {
childViewPager2.requestDisallowInterceptTouchEvent(true);
return false;
});
But, There is another problem. If you have scrollView in ParentViewPager2 and call requestDisallowInterceptTouchEvent(true) in ChildViewPager2 and touch ChildViewPager2, you can't scroll scrollview.
Because when you touch ChildViewPager2, requestDisallowInterceptTouchEvent() called ChildViewPager2 intercept touchEvent.
To solve this problem, you should find another Solution.
'Android' 카테고리의 다른 글
Android(Java) - DatePickerDialog (0) | 2021.01.08 |
---|---|
Android(JAVA) - How to get number of days in this month, YearMonth (0) | 2021.01.07 |
Android(kotlin, java) - LayoutParams, Viewgroup to change margin, width, and height in code (0) | 2020.12.31 |
Android(Java, kotlin) - Appbar Animation with ViewPager inside Fragment (0) | 2020.12.29 |
Android Custom View: Extending The Views (0) | 2020.12.27 |