我有一些文本数据行,可以在0到100之间变化,并且所有文本数据都需要一次在屏幕上显示。对于网格,默认行为是正常的,直到行* rowHeight> gridHeight。

基本上我需要一个挂钩物品高度或行高来根据网格的高度计算它。我已将paddingTop和paddingBottom设置为零,但行之间仍有相当大的空白区域。

我的数据网格组件......

<mx:DataGrid xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="OnCreationComplete()"
paddingTop="0"
paddingBottom="0"
>

<mx:Script>
    <![CDATA[

    private function OnCreationComplete():void
    {
        //setRowHeight(10);
    }

    override protected function setRowHeight(v:Number):void
    {
        super.setRowHeight(v);
    }

    ]]>
</mx:Script>

</mx:DataGrid>

setRowHeight()有帮助,但是如果我将行高设置为10,那么单元格的itemRender大于单元格。

有帮助吗?

解决方案 2

谢谢你的推断,这对我帮助很大。这是我的最终网格组件。由于一些标注,它并不是真正的自包含,但是如果它帮助其他人让他们工作,那就太好了!

<?xml version="1.0" encoding="utf-8"?>
<mx:DataGrid xmlns:mx="http://www.adobe.com/2006/mxml"
paddingTop="-3"
paddingBottom="-3"
resize="OnResize(event)"
>

<mx:Script>
    <![CDATA[
        import mx.containers.Panel;
    import mx.core.Application;
    import mx.events.ResizeEvent;

    protected function OnResize(event:ResizeEvent):void
    {
        this.invalidateDisplayList();
    }

/**
 *  @private
 *  Sizes and positions the column headers, columns, and items based on the
 *  size of the DataGrid.
 */
override protected function updateDisplayList(unscaledWidth:Number,
                                              unscaledHeight:Number):void
{
    if( this.collection.length > 0 ) // so don't divide by zero
    {
        var appHeight:Number = Application.application.height;
        var appMinusMenuHeight:Number = appHeight - Application.application.hboxPrintBar.height;
        var boxHeight:Number = Application.application.vboxViewAll.height;
        if( boxHeight > 0 )
        {
            var gridHeight:Number = (appMinusMenuHeight - this.headerHeight) * 0.93;
            var calcHeight:Number = gridHeight / this.collection.length;
            var calcHeightFloor:Number = Math.floor( calcHeight );
            setRowHeight( calcHeightFloor );
            //var p:Panel = this.parent as Panel;
            //p.title = calcHeightFloor.toString();
            if( calcHeightFloor <= 10 )
                this.setStyle("fontSize",calcHeightFloor);
        }
    }
    super.updateDisplayList(unscaledWidth,unscaledHeight);
}

    ]]>
</mx:Script>

</mx:DataGrid>

其他提示

您可能希望查看DataGrid.variableRowHeight属性,因为当此参数设置为false(默认值)时,所有行的高度都与最大的itemRenderer相同。您还可以考虑为每个DataColumn编写自己的itemRenderer。

如果您真正想要的是根据dataProvider中的项目数设置行高,您可以像这样设置DataGrid.rowHeight属性(假设您的网格具有固定高度,比如说100%) :

myDataGrid.dataProvider = myArray;
myGrid.rowHeight = Math.floor((myGrid.height - myGrid.headerHeight)/myArray.length);

(我在这里发言,因为如果你得到一个向上舍入的小数值,你需要一个滚动条)

正如我认为您注意到的,这种方法的唯一问题是itemRenderer可能无法正确地显示在太小的行中。我想你可以通过根据渲染器的高度更改渲染器中的字体来解决这个问题。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top