当前位置:网站首页>Sliding conflict of view
Sliding conflict of view
2022-07-27 08:38:00 【I'm irrational】
One . Conflict type
There are three types of sliding conflicts , The first is that the external and internal sliding directions are inconsistent , The second type is that the external and internal sliding directions are consistent , The third category is the first two nested patterns .
Rules dealing with these three types fall into two categories , For the first type , We can deal with it according to the sliding direction , Assign to the corresponding control according to the processing direction ; about 2、3 Types , It must be handled according to business differences , The processing event of a certain state is distributed to the corresponding control to process .
When the user slides left and right , Need to let the external View Intercept click events , When users slide up and down , Need to let the inside View Intercept click events . Simply put, whoever slides will intercept . Pictured , According to the sliding process The coordinates of the start and end points We can get whether it is horizontal sliding or vertical sliding .
- According to the included angle formed by the sliding path and the horizontal direction
- According to the distance difference between the horizontal direction and the vertical direction
- According to the speed difference between horizontal and vertical directions
Two . resolvent
1. External interception
So-called External interception Refer to Click events must first be intercepted by the parent container , If the parent container needs this event, it intercepts , Don't intercept if you don't need it , This method is more consistent with the click event distribution mechanism . The external interception method needs to override the parent container's onInterceptTouchEvent Method , Do the corresponding interception inside , The pseudocode is as follows :
public boolean onInterceptTouchEvent(MotionEvent ev) {
boolean intercepted = false;
switch (ev.getAction()){
case MotionEvent.ACTION_DOWN:
intercepted = false;
break;
case MotionEvent.ACTION_MOVE:
if( The parent control needs the current click event ){
intercepted = true;
} else{
intercepted = false;
}
break;
case MotionEvent.ACTION_UP:
intercepted = false;
break;
}
return intercepted;
}
For different sliding conflicts , You only need to modify the condition that the parent container needs the current click event .
stay onInterceptTouchEvent In the method , First of all ACTION_DOWN This event , Parent container must return false, That is, don't intercept ACTION_DOWN event , This is because once the parent container intercepts the event , So the following ACTION_MOVE and ACTION_UP Events are all handled directly by the parent container , Events cannot be passed to child elements ; Next is ACTION_MOVE event , This event can be intercepted as needed , If the parent container needs Intercept Just go back to true, conversely Don't intercept Just go back to false; And finally ACTION_UP event , Here we have to go back to false, because ACTION_UP The event itself doesn't make much sense .
2. Internal interception
Internal interception means that the parent container does not intercept any events , All events are passed to child elements , If the child element needs this event, it consumes , Otherwise, it will be handled by the parent container , This method is inconsistent with the event distribution mechanism , Need to cooperate with requestDisallowInterceptTouchEvent Method can work normally , It's a little more complicated than the external interception method . The pseudocode is as follows :
Subelement :
public boolean dispatchTouchEvent(MotionEvent ev) {
switch (ev.getAction()){
case MotionEvent.ACTION_DOWN:
getParent().requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_MOVE:
if( The parent control needs this click event ){
getParent().requestDisallowInterceptTouchEvent(false);
}
break;
case MotionEvent.ACTION_UP:
break;
}
return super.dispatchTouchEvent(event);
}
For different sliding conflicts , You only need to modify the condition that the parent container needs the current click event .
Except for the child elements that need to be processed , The parent element is also blocked by default ACTION_DOWN Other events , So when the child element calls getParent().requestDisallowInterceptTouchEvent(true) When the method is used , The parent container can continue to intercept the required events .
Parent element :
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
int action = ev.getAction();
if(action == MotionEvent.ACTION_DOWN){
return false;
} else {
return true;
}
}
边栏推荐
- Have a good laugh
- OSI seven layer model and tcp/ip four layer (TCP and UDP) (notes)
- Flink1.15源码阅读flink-clients客户端执行流程(阅读较枯燥)
- Initial summary of flask framework creation project
- 无法获取下列许可SOLIDWORKS Standard,无法找到使用许可文件。(-1,359,2)。
- XxE & XML vulnerability
- "PHP Basics" use of integer data
- SSTI template injection
- Hundreds of people participated. What are these people talking about in the opengauss open source community?
- Vertical align cannot align the picture and text vertically
猜你喜欢

Initial summary of flask framework creation project

好吃难吃饱七分为宜;好喝难喝醉三分为佳

Zhongang Mining: the new energy industry is developing rapidly, and fluorine chemical products have a strong momentum

redis的string类型及bitmap

Interviewer: what is scaffolding? Why do you need scaffolding? What are the commonly used scaffolds?

Vcenter7.0 installation of ibm3650m4 physical machine

海关总署:这类产品暂停进口

Login to homepage function implementation

Cache consistency and memory barrier

Use of flask
随机推荐
我用字符画出了一个谷爱凌!
好吃难吃饱七分为宜;好喝难喝醉三分为佳
Use of flask
693. 行程排序
STM32小bug汇总
[geek challenge 2019] finalsql 1
Map structure
All in one 1353 -- expression bracket matching (stack)
QPushButton 按钮的创建与简单应用
4279. 笛卡尔树
Introduction, installation and use of netdata performance monitoring tool
Block, there is a gap between the block elements in the row
Implementation of adding function of background user management display
User management - restrictions
如何在qsim查看软件对象的实例?
Node installation and debugging
Management of product pictures
User management - restrictions
Bandwidth and currency
Element display mode: block level, inline, inline block, nesting specification, display mode conversion
