a View's onDraw() is called when:

  1. The view is initially drawn
  2. Whenever invalidate() is called on the view

Invalidate can be called by you or the system whenever needed. For example, a lot of Views change how they look onTouch, like an EditText getting an outline and cursor, or a button being in the pressed state. Due to this, Views are redrawn on touch.

I agree that it would be nice to have a document that detailed the working of Views, and if one exists and somebody knows where to find it, please let us know.

  • If you set a background drawable for a View, then the View will draw it for you before calling back to its onDraw() method.

  • onAttachedToWindow () is called when the view is attached to a window. At this point it has a Surface and will start drawing. Note that this function is guaranteed to be called before onDraw(android.graphics.Canvas), however it may be called any time before the first onDraw -- including before or after onMeasure(int, int).

  • invalidate() mark the area defined by dirty as needing to be drawn. If the view is visible, onDraw(android.graphics.Canvas) will be called at some point in the future.

see also:

http://stackoverflow.com/questions/11912406/view-ondraw-when-does-it-get-called

when does the View.ondraw method get called的更多相关文章

  1. ui5 call view or method from another view

    // call view or method from another view //# view call // var view2=sap.ui.jsview("ui5d.popup01 ...

  2. view ondraw

    窗口发生重绘时会被应用程序的窗口框架给调用 要使输出的东西始终能在窗口中看到 就可以使用该函数  窗口从到有的时候就会产生WM_PAINT消息,让窗口发生重绘 这是程序就会执行到ONDRAW函数处 所 ...

  3. torch.Tensor.view (Python method, in torch.Tensor)

    返回具有相同数据但大小不同的新张量.返回的张量共享相同的数据,必须具有相同数量的元素,但可能有不同的大小. Example >>> x = torch.randn(4, 4) > ...

  4. Android 官方文档:(一)动画和图像 —— 1.5 画布和画图

    The Android framework APIs provides a set 2D drawing APIs that allow you to render your owncustom gr ...

  5. The method makeText(Context, CharSequence, int) in the type Toast is not applicable for the arguments (new View.OnClickListener(){}, String, int)

    package comxunfang.button; import android.support.v7.app.ActionBarActivity; import android.os.Bundle ...

  6. 虾扯蛋:Android View动画 Animation不完全解析

    本文结合一些周知的概念和源码片段,对View动画的工作原理进行挖掘和分析.以下不是对源码一丝不苟的分析过程,只是以搞清楚Animation的执行过程.如何被周期性调用为目标粗略分析下相关方法的执行细节 ...

  7. Android 自定义View及其在布局文件中的使用示例

    前言: 尽管Android已经为我们提供了一套丰富的控件,如:Button,ImageView,TextView,EditText等众多控件,但是,有时候在项目开发过程中,还是需要开发者自定义一些需要 ...

  8. View绘制机制

    View 绘制机制 1. View 树的绘图流程 当 Activity 接收到焦点的时候,它会被请求绘制布局,该请求由 Android framework 处理.绘制是从根节点开始,对布局树进行 me ...

  9. 自定义控件(View的绘制流程源码解析)

    参考声明:这里的一些流程图援引自http://a.codekk.com/detail/Android/lightSky/%E5%85%AC%E5%85%B1%E6%8A%80%E6%9C%AF%E7% ...

随机推荐

  1. jQuery 请指出'$'和'$.fn'的区别?或者说出'$.fn'的用途。

    http://hi.baidu.com/chy0806css/item/acc52425099c30ff50fd87eb Jquery为开发插件提供了两个方法,分别是: $.extend(obj);$ ...

  2. css -- 题目汇总

    1.描述下浮动和它的工作原理.模块浮动,使其脱离文档流,并且生成一个块级框.(所以父级撑不开就得到了很好的解释) 2.清除浮动的方法有那些,分别适用于什么情形.clear  ,  父级元素overfl ...

  3. css--block formatting context

    block formatting context(块级格式化上下文) 如何产生BFC:当一个HTML元素满足下面条件的任何一点,都可以产生Block Formatting Context: float ...

  4. ORACLE数据泵还原(IMPDP命令)【转】

      Oracle数据库还原IMPDP命令是相对于EXPDP命令的,方向是反向的.即对于数据库备份进行还原操作.一.知晓IMPDP命令 ? C:\>impdp -help Import: Rele ...

  5. 注册并启动 Reporting Services SharePoint 服务

    在安装 SharePoint 之前已安装 Reporting Services SharePoint 模式.所以Reporting Services SharePoint 是不能正常使用的. 安装完S ...

  6. Xwindow 连接 RHEL 5

    cd /etc/gdm/custom.conf ----------------------------------------- [security] AllowRemoteRoot=true [x ...

  7. JAVA输出图形(网上找的)

    public class TuXing { public static void main(String[] args) { int i, j, k; for (i = 1; i <= 5; i ...

  8. struts2最新s2-016代码执行漏洞CVE-2013-2251

    这是一个代码执行漏洞,利用java代码来执行系统命令.   影响版本:Struts 2.0.0 – Struts 2.3.15   漏洞说明: The Struts 2 DefaultActionMa ...

  9. c++ 普通高精减

    //c++ 普通高精减 //codevs 3115 高精度练习之减法 //内容简单,就不注释了. //注意下,&&优先级高于||. #include<cstdio>#inc ...

  10. svn cleanup failed问题解决

    1.SVN出错 今早过来Update,报如下错误: 再次更新,svn会要求你执行clean up,但执行clean up仍会报错,说有未完的work item,还要求你执行clean up.汗,陷入死 ...