Analysis of key points to solve the sliding jam problem brought by viewpager in Android

Problem Description: when the viewpager control is placed in the swiperefreshlayout, the sliding of the two will conflict with each other. Specifically, the left and right sliding of the viewpager is not smooth, and it is easy to be intercepted by the swiperefreshlayout (that is, a refreshed view appears)

Problem cause: the viewpager itself handles the conflict of scrolling events. When sliding horizontally, it will call the requestdisallowinterceptouchevent() method so that the parent control will not intercept the current touch event sequence. However, the requestdisallowinterceptouchevent() method of swiperefreshlayout does nothing, so it will still intercept the current touch event sequence

Problem analysis: why does the requestdisallowintercepttouchevent () method of swiperefreshlayout do nothing?

First, swiperefreshlayout inherits from ViewGroup

When the requestdisallowintercepttouchevent() method does nothing, the user can pull out the loadingview by pulling down and refreshing once from the bottom. If the method calls the requestdisallowintercepttouchevent() method of ViewGroup, the compatibility problem of viewpager can be solved, but the user cannot continue to pull down after pulling down to the head at the bottom of the interface, You need to release your finger once to pull out the loadingview. Target analysis: in order to scroll more smoothly, of course, the desired effect is to pull out the loadingview at one time. Since the viewpager will call the requestdisallowintercepttouchevent() method when sliding left and right, swipererefreshlayout should only intercept touch events when sliding up and down

The specific logic is as follows:

Record whether the requestdisallowinterceptouchevent() method is called and set to true. Judge whether it is sliding up and down in swiperefreshlayout. If 1 and 2 are met at the same time, call super.requestdisallowinterceptouchevent (true). Otherwise, call super.requestdisallowinterceptouchevent (false) Note: after the requestdisallowinterceptotouchevent method of ViewGroup is set to true, the touch event will be intercepted in the dispatchtouchevent() method, so you need to judge whether it is sliding up and down in the dispatchtouchevent() method

Implementation code (part):

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>