使用固定行计数&扩展Spark DataGrid。没有学者

时间:2011-11-01 19:47:40

标签: flex datagrid resize scale flex-spark

This is resize is scaling by: stage.scaleMode = StageScaleMode.SHOW_ALL; // No Good cause just the Datagrids need to scale

我正在尝试找到一种方法来扩展(字体或缩放X和Y)一个DataGrid(带有requestedMinRowCount = requestedMaxRowCount = requestedRowCount = dataProviderLength),这样它总是会显示所有的行(所以没有滚动条)。

我提出的Scaling解决方案是:

protected function thisDatagrid_resizeHandler(event:ResizeEvent):void
{
   if (event.oldWidth < this.width) {
     this.setStyle('fontSize', this.getStyle('fontSize') + 0.5);
   } else if (event.oldWidth > this.width) {
      this.setStyle('fontSize', this.getStyle('fontSize') - 0.5);
   }
   this.minWidth = this.measuredMinWidth;
}

虽然上面的代码确实调整了Resize上的文本大小(因此是单元格,列和网格),但我得到的问题是重新缩放时是垂直发生的。

要使requestedRowCount正常工作,应该是Datagrid上设置的固定高度。 所以我想知道是什么方法让网格不断显示所有的行和&amp;列缩放(即使垂直调整大小)?

另一个选项将覆盖updateDisplayList,但不能直接调整大小。

override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {

     //super.updateDisplayList(unscaledWidth, unscaledHeight);              
     trace('oldWidth: ' + oldWidth + '  | unscaledWidth: ' + unscaledWidth + '  | parentWidth: ' + this.parent.width);
     trace('oldHeight: ' + oldHeight + '  | unscaledHeight: ' + unscaledHeight + '  | parentHeight: ' + this.parent.height);
     trace('Potential ScaleX: ' + (unscaledWidth - oldWidth)/unscaledWidth);
     trace('Potential ScaleY: ' + (unscaledHeight - oldHeight)/unscaledHeight);
     trace('----------------------------------------------------');
     /* scaleX = (unscaledWidth - oldWidth)/unscaledWidth;
     scaleY = (unscaledHeight - oldHeight)/unscaledHeight; */

     //super.updateDisplayList(unscaledWidth, unscaledHeight);
}

如果我取消注释scaleX&amp; scaleY,它会永远循环......

2 个答案:

答案 0 :(得分:1)

我可能会误解你,但你不能只使用:

<?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">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <s:DataGrid
        id="grid"
        width="100%"
        requestedRowCount="{grid.dataProvider.length}"
        rowHeight="24"
        fontSize="12"
        horizontalScrollPolicy="off"
        verticalScrollPolicy="off">

        <s:dataProvider>
            <s:ArrayCollection>
                <s:source>
                    <fx:Object id="one" label="One" value="1" />
                    <fx:Object id="two" label="Two" value="2" />
                    <fx:Object id="three" label="Three" value="3" />
                </s:source>
            </s:ArrayCollection>
        </s:dataProvider>

        <s:columns>
            <s:ArrayCollection>
                <s:GridColumn dataField="label" headerText="Label" />
                <s:GridColumn dataField="value" headerText="Value" />
            </s:ArrayCollection>
        </s:columns>
    </s:DataGrid>
</s:Application>

答案 1 :(得分:0)

最好的(最高效的方法是使用Datagrids所在的组的布局,并应用如下所示的布局:

ex:ScaleOneLayout.as

import mx.core.UIComponent;

import spark.layouts.BasicLayout;

public class ScaleOneLayout extends BasicLayout
{
    public function ScaleOneLayout()
    {
        super();
    }

    override public function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
   {
        var child:UIComponent;
        child = target.getElementAt(0) as UIComponent;
        child.setLayoutBoundsSize(child.getPreferredBoundsWidth(), child.getPreferredBoundsHeight());
        child.scaleX = unscaledWidth / child.width;
        child.scaleY = unscaledHeight / child.height;
    }
}