View’s sliding conflict and solution in Android

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

A software developer

Leave a Comment

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.