首页 > 学院 > 开发设计 > 正文

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

2019-11-08 00:29:36
字体:
来源:转载
供稿:网友

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.

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()方法,在某种条件下会走该方法的。可以搜其他的源码分析文章,具体查看。源码分析


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表