Home > Mobile >  Two transverse sliding ViewPager2 nested conflict how to solve?
Two transverse sliding ViewPager2 nested conflict how to solve?

Time:09-15

problem scenario : using TabLayout MainActivity + ViewPager2 made a transverse sliding fragments page switching function,
In one of the fragments also USES a ViewPager2 (horizontal), used to turn the contents of the infinite (similar to trill, however is horizontal, vertical effect is not good, I this to lateral),
& nbsp;
map :

Problem of : when display Fragment1, fingers in Fragment1 ViewPager2 sliding, I want to trigger this slide, trigger is ViewPager2 sliding in the Activity, however,
ViewPager2 is final class cannot copy, source of isUserInputEnabled () to True onInterceptTouchEvent will intercept, someone give me method is when Fragment1 showed that the Activity of ViewPager2 isUserInputEnabled () is set to False, but I need in other areas of the Fragment1 except ViewPager2 and can trigger Activity in ViewPager2 sliding,
Can you tell me how to solve?

CodePudding user response:

https://blog.csdn.net/weixin_43917449/article/details/86519726

CodePudding user response:

reference 1/f, no fucker said reply:
https://blog.csdn.net/weixin_43917449/article/details/86519726

ViewPager can copy, so can be control event distribution, but ViewPager2 there's no way.

CodePudding user response:

refer to the second floor Moriafly response:
Quote: reference 1/f, no fucker said reply:
https://blog.csdn.net/weixin_43917449/article/details/86519726

ViewPager can copy, so can be control event distribution, but ViewPager2 there's no way.

Inside all write very clear, in child Viewpager intercept consumption, baidu Viewpager nested Viewpager a heap

CodePudding user response:

reference no 4th floor fucker response:
Quote: refer to the second floor Moriafly response:
Quote: refer to 1st floor without fucker said reply:
https://blog.csdn.net/weixin_43917449/article/details/86519726

ViewPager can copy, so can be control event distribution, but ViewPager2 there's no way.

Inside all write very clear, in child Viewpager intercept consumption, baidu Viewpager nested Viewpager a heap of
eldest brother, is ViewPager2, 22222, the second generation, cannot rewrite the intercept events, website: https://developer.android.google.cn/jetpack/androidx/releases/viewpager2, is not the Viewpager, Viewpager I will,

CodePudding user response:

reference no 4th floor fucker response:
Quote: refer to the second floor Moriafly response:
Quote: refer to 1st floor without fucker said reply:
https://blog.csdn.net/weixin_43917449/article/details/86519726

ViewPager can copy, so can be control event distribution, but ViewPager2 there's no way.

Inside all write very clear, in child Viewpager intercept consumption, baidu Viewpager nested Viewpager a heap of

CodePudding user response:

I solved this problem,
I solve so ViewPager2 is a final class cannot be inherited, rewrite onInterceptTouchEvent, but change the idea, I will ViewPager2 in parent layout,
Here I am using ConstraintLayout, then inherit ConstraintLayout, rewrite onInterceptTouchEvent,
So by clicking the calculate click on the location and the height of the child ViewPager2, whether I can come to click on the location of the within the child ViewPager2,
Override fun onInterceptTouchEvent (ev: MotionEvent? : Boolean {
Ev? . Let {
If (ev) action==MotionEvent) ACTION_DOWN) {
OnOutsideTouchListener. Invoke (
Ev. Y & gt; GetChildAt (0). The height
)
}
}
Return super. OnInterceptTouchEvent (ev)
}
And then by passing in the closure, you can gain clickable area, you can have a try,
  • Related