From 2829898ed71173e82716a08b71e1181f076b6a4c Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Mon, 23 May 2016 16:44:45 +0800 Subject: [PATCH] fix layout resize container mode issue 1. when disable some child node, the base width/height is not updated. --- cocos2d/core/components/CCLayout.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/components/CCLayout.js b/cocos2d/core/components/CCLayout.js index e894709da1..a6656ace17 100644 --- a/cocos2d/core/components/CCLayout.js +++ b/cocos2d/core/components/CCLayout.js @@ -505,12 +505,17 @@ var Layout = cc.Class({ _getVerticalBaseHeight: function (children) { var newHeight = 0; + var activeChildCount = 0; if (this.resizeMode === ResizeMode.CONTAINER) { children.forEach(function(child) { + if (!child.activeInHierarchy) { + return; + } + activeChildCount++; newHeight += child.height; }); - newHeight += (children.length - 1) * this.spacingY + 2 * this.padding; + newHeight += (activeChildCount - 1) * this.spacingY + 2 * this.padding; } else { newHeight = this.node.getContentSize().height; @@ -755,11 +760,16 @@ var Layout = cc.Class({ _getHorizontalBaseWidth: function (children) { var newWidth = 0; + var activeChildCount = 0; if (this.resizeMode === ResizeMode.CONTAINER) { children.forEach(function(child) { + if(!child.activeInHierarchy) { + return; + } + activeChildCount++; newWidth += child.width; }); - newWidth += (children.length - 1) * this.spacingX + 2 * this.padding; + newWidth += (activeChildCount - 1) * this.spacingX + 2 * this.padding; } else { newWidth = this.node.getContentSize().width;