How are views added to screen Windows

The system creates a top-level layout container, a DecorView, which is a ViewGroup container that inherits from Framlayout and is an instance held by the phoneWindow object, which is the top-level View of all applications and initialized internally. When the DecorView is initialized, a base container is loaded based on the theme nature of the application, such as NoActionBar. The base container is loaded differently for different themes. But anyway, there’s always going to be a container with a Content id, and that container is Framlayout, and the setContentView that we set is going to be parsed into that Framlayout.

Definition of events

Definition: Touch events that occur when the user touches the screen

The event type

ACTION_UP Release MotionEvent from the screen.ACTION_MOVE Swipe MotionEvent.ACTION_CANCEL on the screen The non-human factor is eliminatedCopy the code

Sequence of events

Normally, a finger touching the screen triggers a series of clicks

  • Click the screen and release it immediately. The sequence of events is DOWN->UP
  • Click the screen to slide for a while and then release it. The sequence of events is DOWN->MOVE->···MOVE->UP

The object to which the event is distributed

  • Activity: Controls the life cycle & handles events
  • 14. ViewGroup: a collection of views (including multiple sub-views)
  • View: Base class for all UI components

The main method of event distribution

  • DispatchTouchEvent (MotionEvent EV): Used for event distribution
  • OnInterceptTouchEvent (MotionEvent EV): Determines whether to intercept an event (only in ViewGroup)
  • OnTouchEvent (MotionEvent EV): Handles click events

Event distribution model