当前位置:首页 > 未命名 > 正文内容

View's sliding conflict and solution in Android

u3blog8年前 (2016-03-15)未命名239

What is sliding conflict

When two layers can be sliding in the interface, system don't know how to dispatch the sliding event right, the sliding conflict happened. A typical scenario is add listview into ViewPager, sliding conflict shown up, you can't sliding listview.

Common type of sliding conflict scenarios

There are mainly three scenarios of sliding conflict 1.Scenario 1 - external internal sliding direction is inconsistent 2.Scenario 2 - external and internal sliding in the same direction 3.Scenario 3 - a mix of scenario 1 and scenario 2 see the pic: 2016-03-10 20-23-48屏幕截图

The principle of deal with sliding conflict

Deal with sliding conflict, we can follow these principle Scenario 1,we can dispatch event by direction or speed Scenario 2, we can dispatch event by business status Scenario 3, same as Scenario 2

detail solution

Scenario 1,there are two way to solve it 1.external intercept 1.1 ACTION_DOWN event return false in parent view's onInterceptTouchEvent(MotionEvent event) methods, if not the seriars of event can't dispatch to child view again. 1.2 For ACTION_MOVE event,we should charge by our principle to return true or false. 1.3 For ACTION_UP event, return FALSE, if not child view can't invoke onclick() method. 2.interior intercept 2.1 handle in the child view, but need use requestDisallowInterceptTouchEvent method, rewrite onInterceptTouchEvent method, if child view not deal with this event, invoke parent.requestDisallowInterceptTouchEvent(false) to send this event to parent. 2.2 Parent view can't intercept ACTION_DOWN. For scenario 2 and 3, we need combine business statues to hand it. There are a lot of sample in internet with how to deal sliding conflict, so i don't put it here again

扫描二维码推送至手机访问。

版权声明:本文由u3blog发布,如需转载请注明出处。

本文链接:https://u3blog.xyz/?id=287

分享给朋友:

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。