2020 quit manufacturers, the most frequently asked 9 Custom View face questions! Collection [recommendation]

Note: Because the actual development with reference to the answer will be different. Furthermore afraid mislead you, so they still face questions answer themselves to understand! Deep knowledge questions for the interviewer will resume point mentioned, so do not answer back, more understanding.

Speak draw process under the View?

  • Reference answer:
    • Main View workflow refers measure, layout, draw these three processes, i.e. the measurement, and the layout drawing, wherein determining the measure of View measured width / height , determined layout View of the final width / height and position of the four vertices , and View draw will be drawn to the screen on
    • View of the drawing process follow the following steps:
      • Draw background  background.draw (canvas)
      • Draw your own (onDraw)
      • Drawing Children (dispatchDraw)
      • Drawing decorative (onDrawScollBars)

2. What MotionEvent that? It contains several events? Under what conditions will produce?

  • Reference answer:
    • MotionEvent is a series of events after the finger touches the screen produced. Typical event types are as follows:
      • ACTION_DOWN : new to the screen finger
      • ACTION_MOVE : move your finger on the screen
      • ACTION_UP : Release your finger from the screen the moment
      • ACTION_CANCELL : finger held down operations and move from the current control to the outer layer of control fires
    • Under normal circumstances, one finger touches the screen's behavior will trigger a series of events clicks, consider the following situations:
      • After clicking the screen release, the sequence of events: DOWN → UP
      • Tap the screen to slide for a while and then release, the sequence of events was DOWN → MOVE → ..... → MOVE → UP

3. Describe View event delivery distribution mechanism?

  • Reference answer:
    • View event distribution process is essentially to MotionEvent event distribution. That is, when a MotionEvent occurs, the system will be delivered to the click event on a specific View
    • Click on the event delivery order: Activity (Window) → View → ViewGroup
    • Event distribution process jointly carried out by three methods:
      • dispatchTouchEvent : used to distribute event. If the event can be transferred to the current View, then this method will be called, returns the result affected dispatchTouchEvent method of onTouchEvent and subordinates View current View indicating whether the consumption of current events
      • onInterceptTouchEvent : inside the method call, the incident interception. This method has only ViewGroup, View (ViewGroup not included) is not. Once intercepted, onTouchEvent ViewGroup is executed, processing events in ViewGroup, without the then distributed to View. And only called once, returning a result indicating whether the interception Current events
      • onTouchEvent : In dispatchTouchEvent method call to handle click events, returns a result indicating whether the consumption of current events

4, how to solve the View event of a conflict? For example encountered in the development?

  • Reference answer:
    • There ScrollView sliding conflict with RecyclerView common development in the event of conflict, RecyclerView embedded while sliding in the same direction
    • Slide the conflict processing rules:
      • Conflict due to external slide and slide inside the sliding direction caused by the inconsistency, who may be determined according to the direction of sliding intercept events.
      • For sliding conflict due to external and internal sliding direction of the sliding direction of the same cause, according to business needs dictate when to let external events View interception, when intercepted by an internal event View.
      • For nested above two cases, relatively complex, can also be found breakthrough in business on demand.
    • Slide implementation of conflict:
      • External intercept method : finger tap events are first processed through the interception of the parent container, if the parent container need this event to intercept, or not intercepted. Specific methods: a method to rewrite onInterceptTouchEvent parent container, made inside corresponding intercept.
      • Internal intercept method : refers to the parent container does not intercept any event, and all events are passed to the child container, the container needs child if this event directly consumed, otherwise the process will be handed over to the parent container. Specific methods: need to meet requestDisallowInterceptTouchEvent method.

5, scrollTo () and scollBy () of the difference?

  • Reference answer:
    • Internal scollBy calls scrollTo, which is based on the current position relative sliding; and scrollTo is absolutely slide, so if you use the same input parameters call scrollTo method multiple times, due to the initial position View is constant, so only once to scroll View Effect
    • Both can only slide on the View content, rather than the View slide itself. Scroller can use excessive sliding effect
  • recommended article:

6, Scroller is how to achieve flexibility View slide?

  • Reference answer:
    • Call startScroll () method when MotionEvent.ACTION_UP event is triggered, the method does not perform the actual operation of the slide, but the records related to the amount of sliding (sliding distance, sliding time)
    • Next call invalidate / postInvalidate () method, View redraw request, the method is executed cause View.draw
    • When calls View draw redraw process computeScroll method and computeScroll Scroller will get the current whereabouts and scrollY scrollX; scrollTo then achieved by a sliding method; and then call a second method postInvalidate redraw, and before the process Like so repeatedly led to View the ongoing slide a small margin, but many times a slight slip on the formation of elastic slide, slide through to the end until the entire

       

7, invalidate () and postInvalidate () of the difference?

  • Reference answer:
    • invalidate () and postInvalidate () are used to refresh View, the main difference is invalidate () call in the main thread, if used in the child thread needs to cooperate handler; and postInvalidate () can be called directly in the child thread.

8, SurfaceView and View of difference?

  • Reference answer:
    • View picture needs to be refreshed in the UI thread, and SurfaceView can refresh the page in the child thread
    • View update applies to the case of active, passive and SurfaceView applies to updates, such as frequent refresh, because if you use View frequently refresh will block the main thread, leading to interface Caton
    • SurfaceView realized in the underlying double buffering mechanism, and no View, SurfaceView therefore more suitable for frequent refresh, refresh large amount of data processing when a page (such as a video player interface)

9. Custom View consider how models fit?

  • Reference answer:
    • Rational use warp_content, match_parent
    • As is the use of RelativeLayout
    • For different models, use a different layout under the corresponding file in the directory, android will match automatically.
    • Try to use point 9 picture.
    • Using pixel-density-independent dp, sp
    • The introduction of android percentage layout.
    • FIG cut when cutting large FIGS resolution, which is applied to the layout. In the resolution on small phone will have a good display.

Alibaba Andorra face questions over the years to see the blog set-top;

https://blog.csdn.net/chuhe1989/article/details/104804567

Published 56 original articles · won praise 1 · views 2901

Guess you like

Origin blog.csdn.net/chuhe1989/article/details/104848602