【问题标题】:requestLayout() improperly called by RelativeLayout被RelativeLayout错误调用的requestLayout()
【发布时间】:2015-07-20 17:31:21
【问题描述】:

我有一个自定义 FrameLayout,在 xml 文件中它有 2 个孩子(它们都是 RelativeLayout,它们相互重叠)

drawChild 方法中我这样做

 protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    if(view.equals(firstChild){
       return super.drawChild(canvas, child, drawingTime);
    }else {
     //...do some thing with mPath like adding a circle to it
     canvas.clipPath(mPath);
     return super.drawChild(canvas, child, drawingTime);
   }
}

但是我从 Logcat 得到了这两行代码:

requestLayout() improperly called by android.widget.RelativeLayout{c1a8b57 V.E...... ......ID 0,0-1080,210} during second layout pass: posting in next frame
requestLayout() improperly called by android.widget.RelativeLayout{c1a8b57 V.E...... ......ID 0,0-1080,210} during layout: running second layout pass

我知道clipPath 有问题(可能重叠),因为通过评论此行canvas.clipPath(mPath); 警告消失了。

有什么想法吗?

【问题讨论】:

  • “如果我将第二个孩子的可见性更改为 GONE”,这将导致第二个孩子永远无法测量、布局和绘制。
  • @petey 是的,我知道,我编辑了我的问题

标签: android


【解决方案1】:

我会做三件事:

首先,我会检查 canvas.clipPath() 与您的目标 API 版本的兼容性,它应该是 18 或更高版本。

其次,我会检查您声明 Path 对象(mPath)的位置和方式。

第三,我会确保在您尝试使用 clipPath() 时画布已经存在。此外,这可能不是问题,但根据 FrameLayout 的 API:子视图绘制在堆栈中,最近添加的子视图位于顶部,因此请确保您正在使用的子视图可访问。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多