/ Published in: ActionScript 3
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
override public function measure():void { if (!useVirtualLayout) return; var layoutTarget:GroupBase = target; if (!layoutTarget) return; var dataGroupTarget:DataGroup = layoutTarget as DataGroup; if (dataGroupTarget.width == 0 || dataGroupTarget.height == 0) { _containerWidth = _containerHeight = -1; return; } var totalWidth:Number = 0; var totalHeight:Number = 0; var dataProvider:IList = dataGroupTarget.dataProvider; if (!dataProvider || !dataProvider.length) return; var count:int = dataProvider.length; var rowWidth:Number = dataGroupTarget.width; var sectionHeight:Number = _sectionHeight; var tileHeight:Number = _tileHeight; var tileWidth:Number = _columnWidth; totalWidth = rowWidth; var elementWidth:Number, elementHeight:Number; var x:Number = 0; yToIndex = new Vector.<int>(); indexToY = new Vector.<int>(); var d:Object = d = dataProvider.getItemAt(0); if (_sectionLabel in d) { addToVectorY(0, 0, sectionHeight); totalHeight = sectionHeight + _verticalGap; } else { addToVectorY(0, 0, tileHeight); totalHeight = tileHeight + _verticalGap; } //loop though all the elements elements for (var i:int = 0; i < count; i++) { d = dataProvider.getItemAt(i); if (!d) { elementWidth = tileWidth; elementHeight = tileHeight; } else if (_sectionLabel in d) { elementWidth = rowWidth; elementHeight = sectionHeight; } else { elementWidth = tileWidth; elementHeight = tileHeight; } // Would this element fit on this line, or should we move it // to the next line? if (x + elementWidth > rowWidth) { x = 0; //add the index to vector addToVectorY(i, totalHeight + 1, elementHeight); totalHeight += elementHeight + _verticalGap; } addToVectorIndex(i, totalHeight - elementHeight - _verticalGap); // Update the current position, add the gap x += elementWidth + _horizontalGap; } layoutTarget.measuredWidth = totalWidth; layoutTarget.measuredHeight = totalHeight; layoutTarget.measuredMinWidth = totalWidth; layoutTarget.measuredMinHeight = totalHeight; layoutTarget.setContentSize(totalWidth, totalHeight); }
URL: http://corlan.org/?p=2987