AdvancedDataGrid 是画布中唯一的东西吗?
我会将 AdvancedDataGrid 的大小调整为完整的高度和宽度,并让 Canvas 处理滚动。
在画布中,覆盖 updateDisplayList 方法并执行以下操作:
protected function updateDisplayList(unscaledWidth: Number, unscaledHeight: Number):void{
super.updateDisplayList, unscaledHeight);
this.myAdvancedDataGrid.setActualSize(this.myAdvancedDataGrid.measuredHeight, this.myAdvancedDataGrid.measuredWidth );
}
这样 AdvancedDataGrid 应该没有滚动条。但是,如果它延伸到极下方或太右,滚动条将出现在画布中。
您可能会受益于阅读Flex Coordinate System。AdvancedDataGrid 是您的“内容”,而 Canvas 将是您的本地。
我正在添加一个完整的运行代码示例来演示我的建议。
这是内部带有 AdvancedDataGrid 的画布组件:com.flextras.stackOverflow.CanvasWithGrid
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
super.updateDisplayList(unscaledWidth, unscaledHeight);
this.myADG.setActualSize(this.myADG.measuredWidth, this.myADG.measuredWidth );
}
[Bindable]
private var dpFlat:ArrayCollection = new ArrayCollection([
{Region:"Southwest", Territory:"Arizona",
Territory_Rep:"Barbara Jennings", Actual:38865, Estimate:40000},
{Region:"Southwest", Territory:"Arizona",
Territory_Rep:"Dana Binn", Actual:29885, Estimate:30000},
{Region:"Southwest", Territory:"Central California",
Territory_Rep:"Joe Smith", Actual:29134, Estimate:30000},
{Region:"Southwest", Territory:"Nevada",
Territory_Rep:"Bethany Pittman", Actual:52888, Estimate:45000},
{Region:"Southwest", Territory:"Northern California",
Territory_Rep:"Lauren Ipsum", Actual:38805, Estimate:40000},
{Region:"Southwest", Territory:"Northern California",
Territory_Rep:"T.R. Smith", Actual:55498, Estimate:40000},
{Region:"Southwest", Territory:"Southern California",
Territory_Rep:"Alice Treu", Actual:44985, Estimate:45000},
{Region:"Southwest", Territory:"Southern California",
Territory_Rep:"Jane Grove", Actual:44913, Estimate:45000}
]);
]]>
</fx:Script>
<mx:AdvancedDataGrid id="myADG"
initialize="gc.refresh();"> <!-- width="100%" height="100%" -->
<mx:dataProvider>
<mx:GroupingCollection id="gc" source="{dpFlat}">
<mx:grouping>
<mx:Grouping>
<mx:GroupingField name="Region"/>
<mx:GroupingField name="Territory"/>
</mx:Grouping>
</mx:grouping>
</mx:GroupingCollection>
</mx:dataProvider>
<mx:columns>
<mx:AdvancedDataGridColumn dataField="Region"/>
<mx:AdvancedDataGridColumn dataField="Territory"/>
<mx:AdvancedDataGridColumn dataField="Territory_Rep"
headerText="Territory Rep"/>
<mx:AdvancedDataGridColumn dataField="Actual"/>
<mx:AdvancedDataGridColumn dataField="Estimate"/>
</mx:columns>
</mx:AdvancedDataGrid>
</mx:Canvas>
这是主要的应用程序文件:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:stackOverflow="com.flextras.stackOverflow.*">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<stackOverflow:CanvasWithGrid width="200" height="200" />
</s:Application>