Mobile Development: Do you think the event distribution is very simple, but I was asked to cry ...

Mobile Development: Do you think the event distribution is very simple, but I was asked to cry ...

Today first day of work for everyone some fun, tell us something about the event distribution, you might smile:. "Do not get me Yeah, event distribution who do not know it."

However, today's content, you may not really know.

Note: If you distribute the principle events not sure about, you need first to know enough about the event distribution, and finally subsequent reading.

The following text beginning, because this problem is to produce and exchange between colleagues, so this presented in dialogue form.

protagonist:

Small A, small B.

Small A: B ah, you give I talk about events concise distribution process.

Small B: Go ahead.

"Event is a process for distributing a gesture, this gesture contains a ACTION_DOWN, many times ACTION_MOVE, and once ACTION_UP", in ACTION_DOWN to decide when this incident "TargetView", the View will determine the distribution of the incident flow of events .

In the case of the parent control can ACTION_DOWN or targetView not empty, intercept, if intercepted targetView event, it will send a ACTION_CANCEL.

Small A: answer Yes I can, I'll test you a few questions.

Small B: Although come.

Small A: You say there will be an event distribution process many times ACTION_POINT_DOWN it?

B Small hearts: This is not what to send sub-themes, evidently A small piece of multi-fingered brothers for not familiar with it, it can be used as a problem.

Small B: Sure, multi-finger when you press the first finger, and then press the second finger ACTION_POINTER_DOWN came.

You can look at ViewPager, ScrollView these official source category, there are multi-finger treatment.

Small A: ghostly smile, and then I ask you, an event distribution process, there may be multiple ACTION_DOWN it?

Small B: and so, if I got it, a bottle of Coke.

Small A: Good.

Small B: No, only your first finger is pressed ACTION_DOWN, are ACTION_POINTER_DOWN start from the second, of course, the premise is you do not modify dispatchTouchEvent distribution logic Kazakhstan, that can not change, is not going to buy Coke a.

Small A: Well, finally I ask you a specific question, there are two internal LinearLayout a Button, when I first finger on the first Button, second finger on the second Button, which Button which will receive two ACTION_DOWN? Lift each finger separately, which would be triggered Click the Button?

Small B: of course, was the first to receive ACTION_DOWN, it should also be able to trigger the first click.

Small A: Not bad, you go to do an experiment and then decide whether or not I buy a Coke.

Conversation ends.

Here we like to think how small B answer?

First do not look down, to think of what your answer should be, if wrong, let me have a bottle of Coke.

Small B back test.

Yelled out: for coke!

Fast finish Demo, into a customized MyLinearLayout, MyButton, replication dispatchTouchEvent, marked Event log, plus the onclick event log.

As previously described experiments:

There are two internal LinearLayout a Button, when I first finger on the first Button, second finger on the second Button, Button which both receive ACTION_DOWN? Lift each finger separately, which would be triggered Click the Button?

See Log, sank.

The first finger is pressed on the first Button, Button first to receive ACTION_DOWN.
The second finger on the second Button, Button second actually also received ACTION_DOWN.

When were lifted, two Button's Click turn triggers.

Note: when we tested, Button can engage in larger, two Button distance farther, to prevent inadvertently.

Small B with two bottles of Coke came to the small A, hastened to tell me about her brother.

Small A:

Well, very early, a lot of blog event distribution of the code is based on the 2.x series, and that the code would look like this:

Mobile Development: Do you think the event distribution is very simple, but I was asked to cry ...

See complete code here

MotionTarget is a View. In the subsequent code, "targetView" is no longer a separate View, but rather a similar list.

// First touch target in the linked list of touch targets.
private TouchTarget mFirstTouchTarget;

private static final class TouchTarget {

    // The touched child view.
    public View child;

    // The next target in the target list.
    public TouchTarget next;
}

You see the difference down the source code to understand.

Small B: This wave is not loss, although the loss of two bottles of Coke, but learned.

Well, AB role ended, the conversation is basically a daily dialogue with colleagues, of course, I deliberately touches a little.

Once again Tips: In the interview, do not deliberately show off you know of an event distribution logic may have more ACTION_DOWN, have to make the situation clear, because the interviewer is likely to have not read this article and hang you do not blame me. ..

At last

In fact, for programmers, content knowledge to learn, there are too many technical, environmental order not to be eliminated only improve ourselves, always us to adapt to the environment, not the environment to adapt to us!

Here attached the above-mentioned technical system diagram related to dozens of sets of Tencent, headlines, Ali, the US group and other companies face questions 19 years , the technology has become a finishing point video and PDF (in fact, spend a lot of time than expected) including knowledge context + many details , because of space limitations, here in the form of pictures to show you part of it.

I believe it will bring you a lot of harvest:

Mobile Development: Do you think the event distribution is very simple, but I was asked to cry ...

Mobile Development: Do you think the event distribution is very simple, but I was asked to cry ...

[HD brain diagram above], and [supporting] PDF technology architecture can add me wx: X1524478394 free access!

When programmers easily, when a good programmer is a need to learn from junior programmer to senior programmer, architect from primary to senior architect, or to management, technical director from technical manager to each stage We need to have different capabilities. Early to determine their career direction, in order to throw off their peers at work and in capacity building.

Finally, if you and a small B as wrong, cola I do not, you can point a praise it ~

Mobile Development: Do you think the event distribution is very simple, but I was asked to cry ...

Guess you like

Origin blog.51cto.com/14332859/2464752