android: requestLayout (), invalidate (), postInvalidate () method distinction

A, invalidate and postInvalidate

  These two methods are redrawn in the current control when called. invalidate the UI thread calls, postInvalidate called in non-UI thread. Because the UI thread is not thread-safe android, so in a non-UI thread, use the View postInvalidate to redraw. view call invalidate the current view will lead to redraw (draw calls), view of the parent class will not execute the draw method; viewGroup call child will invalidate the view viewGroup calls draw, that is, the child view inside the viewGroup redrawn;

 

二、requestLayout

  requestLayout method will only lead to the current view of the measure and layout, while the draw is not necessarily to be executed only when the position of view is changed will perform the draw method, so if you want to redraw the current view need to call invalidate.

 

Three, onLayout

  In many cases requestLayout it does not need to be called. For example, we have a AbsoluteLayout move about inside childView position. Probably just need to call us to re-layout of the current AbsoluteLayout, then call invalidate method to redraw. Rather than re-layout from the current overall View tree View up to be, onLayout, measure, onMeasure once. In this case you can call onLayout directly. Then call invalidate redrawn. Obviously we can improve rendering efficiency. As the parent View layout to achieve the listener will be notified of the layout. However, due to not get listener, so the call onlayout when it can not be notified of this flaw and this is achieved.

 

Guess you like

Origin www.cnblogs.com/yongdaimi/p/11080940.html