自定义控件基础 requestLayout()和invalidate()区别

来源:互联网 发布:java swing选择控件 编辑:程序博客网 时间:2024/06/08 20:10
  1. requestLayout():
    重新布局整个ViewTree,开始调用measure()方法。
    requestLayout()是view的方法,view也可以调用该方法。

    Call this when something has changed which has invalidated the layout of this view. This will schedule a layout pass of the view tree. This should not be called while the view hierarchy is currently in a layout pass.
  2. invalidate():
    如果当前View可见,onDraw()方法将会被调用。

    Invalidate the whole view. If the view is visible, onDraw() will be called at some point in the future.This must be called from a UI thread. To call from a non-UI thread, call postInvalidate().

在写SimpleIndicator时,并不是一定不会走onMeasure()方法,在某种条件下会走该方法的。可以搜其他的源码分析文章,具体查看。源码分析

0 0
原创粉丝点击