• Android ViewGroup


    一、概述

    二、注意事项

    1. 在派生类中,重写onDraw(...)方法,如果不给LinearLayout设置一个背景,系统是不会调用onDraw时,也就是说,我们重写的onDraw(...)是不会调用的。当设置一个背景后,onDraw就会被调用。ViewGroup本身是一个容器,其本身并没有任何东西可以绘制,它是一个透明的控件,所以,不给调用onDraw(...)方法。

     1 /**
     2  * If this view doesn't do any drawing on its own, set this flag to
     3  * allow further optimizations. By default, this flag is not set on
     4  * View, but could be set on some View subclasses such as ViewGroup.
     5  *
     6  * Typically, if you override {@link #onDraw(android.graphics.Canvas)}
     7  * you should clear this flag.
     8  *
     9  * @param willNotDraw whether or not this View draw on its own
    10  */
    11 public void setWillNotDraw(boolean willNotDraw) {
    12     setFlags(willNotDraw ? WILL_NOT_DRAW : 0, DRAW_MASK);
    13 }

      上面的解释可以看出,想重写ViewGroup.onDraw(...)方法,应该调用这个方法将flag清除。在构造方法中,调用setWillNotDraw(...)方法。

    三、参考资料

    1. 为什么ViewGroup onDraw方法不被调用?

  • 相关阅读:
    Lua 的元表怎么理解
    Lua中的元表与元方法
    Lua 的元表怎么理解
    VMware Workstation 系统备份-虚拟机克隆方法
    Lua中的元表与元方法
    bzoj2809
    bzoj2733
    bzoj1334
    bzoj1211
    bzoj3083 3306
  • 原文地址:https://www.cnblogs.com/naray/p/5720932.html
Copyright © 2020-2023  润新知