2013-08-23 70 views
0

我需要縮進標籤。設置頂部,底部,左側的屬性不起作用。DefaultGridItemRenderer中的Flex 4.5位置標籤

<?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> 

回答

0

我認爲控制對齊的最好方法是將你的組件集成到一個組中。

這裏是一個效果可以達到:

enter image description here

下面是代碼:

//應用

<?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> 
+0

我w ^作爲使用一個組和由於性能的原因,我想刪除額外的容器,因爲我不需要它。 – Alexander