0

我需要缩进标签。设置 de 属性 top, bottom, left 不起作用。

<?xml version="1.0" encoding="utf-8"?>
<s:DefaultGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                           xmlns:s="library://ns.adobe.com/flex/spark" 
                           xmlns:mx="library://ns.adobe.com/flex/mx" top="10" bottom="10"
                           left="{data != null ? left = (data.niveau-1) * 20 : ''}">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>
        <![CDATA[           
            override public function prepare(willBeRecycled:Boolean):void{
                if(data != null){
                    label = data.tekst;
                    styleName= 'niveau'+data.niveau;                    
                    toolTip=data.hulptekst;                 
                }
            }

        ]]>
    </fx:Script>
</s:DefaultGridItemRenderer>
4

1 回答 1

0

我认为控制对齐的最佳方法是将您的组件集成到一个组中。

这是您可以实现的效果:

在此处输入图像描述

这是代码:

//应用程序

<?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">
<fx:Script>
    <![CDATA[
        import mx.collections.ArrayCollection;

        [Bindable]private var myDP:ArrayCollection = new ArrayCollection([
            {myfield:"Hello", niveau:3},
            {myfield:"World", niveau:7},
            {myfield:"!!!", niveau:5}
        ]); 
    ]]>
</fx:Script>

<s:DataGrid id="myDG" x="20" y="20" height="120" dataProvider="{myDP}" editable="true">
    <s:columns>
        <s:ArrayList>
            <s:GridColumn dataField="myfield" headerText="My Field" width="170" itemRenderer="renderers.CustomRenderer"/>       
            <s:GridColumn dataField="myfield" headerText="My Field" width="170"/>
        </s:ArrayList> 
    </s:columns >
</s:DataGrid>

</s:Application>

//渲染器

<?xml version="1.0" encoding="utf-8"?>
<s:GridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                xmlns:s="library://ns.adobe.com/flex/spark" 
                xmlns:mx="library://ns.adobe.com/flex/mx" clipAndEnableScrolling="true">
<fx:Script>
    <![CDATA[
        override public function prepare(hasBeenRecycled:Boolean):void {
            lblData.text = data[column.dataField]
        }
    ]]>
</fx:Script>

<s:Group width="100%" height="100%">
    <s:Label id="lblData" top="9" left="{data != null ? (data.niveau - 1) * 20 : 0}"/>      
</s:Group>

</s:GridItemRenderer>
于 2013-09-08T16:54:42.893 回答