2012-07-18 48 views
1

我正在創建一個顯示Flex新聞列表的移動應用程序。Flex列表:與第一個項目不同的出現

每個新聞都有一個標題和一張圖片,所以我使用帶有iconItemRenderer的列表來顯示結果。看來itemRenderers總是給所有項目出現相同的出現。

但我想給出第一個項目不同的外觀,全幅照片和更大的標題。我不知道該怎麼做。

有什麼想法?

+1

如何創建自定義渲染器? – 2012-07-18 07:54:09

+0

你的意思是在actionscript中定製一個itemRenderer類?我在嘗試:我按照這個教程[鏈接](http://www.youtube.com/watch?v=EOpsDZaQrOI),但我沒有看到你可以'抓住'第一個項目 – user1076149 2012-07-18 08:19:52

+2

你應該能夠使用itemRendererFunction爲第一個項目使用不同於其他渲染器的渲染器。 – JeffryHouser 2012-07-18 13:01:12

回答

0

您應該使用自定義組件並重寫一些基本方法。所以,我試圖做到這一點,但面臨一些問題。可能是這個問題沒有在flex 3中修復(我使用flex 3 :-))。 因此,儘管這我找到了解決辦法。

import mx.controls.List; 
import mx.core.IFactory; 

public class ListEx extends List{ 

    public function ListEx(){ 
     super(); 
    } 

    public var item1stRenderer:IFactory; 
    public var item1stCount:int=1; 
    private static var _first:int = 0; 

    override public function getItemRendererFactory(data:Object):IFactory{ 
     if(_first<=item1stCount && item1stRenderer != null && data != null){ 
      return item1stRenderer; 
     }else{ 
      return super.getItemRendererFactory(data); 
     } 
    } 

    override public function get itemRenderer():IFactory{ 
     if(_first<=item1stCount && item1stRenderer != null){ 
      _first++; 
      return item1stRenderer; 
     }else{ 
      return super.itemRenderer; 
     }   
    }  
} 

讓我們來測試一下!

<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" height="100%" width="100%" xmlns:local="*"> 

    <mx:Model id="mystates"> 
     <states> 
      <state label="Alabama" data="AL"/> 
      <state label="Alaska" data="AK"/> 
      <state label="Arizona" data="AZ"/> 
      <state label="Arkansas" data="AR"/> 
      <state label="California" data="CA"/> 
      <state label="Colorado" data="CO"/> 
      <state label="Connecticut" data="CT"/> 
     </states> 
    </mx:Model> 

    <local:ListEx itemRenderer="mx.controls.TextInput" id="g_list" dataProvider="{mystates.state}" width="100%"> 
     <local:item1stRenderer> 
      <mx:Component> 
       <mx:Label color="blue"/> 
      </mx:Component> 
     </local:item1stRenderer> 
    </local:ListEx> 

</mx:Application> 

希望,我可以幫助你。

PS:抱歉我的英語,我是俄語演講:)

+0

正如你所看到的,兩種方法必須被覆蓋,可能有bug – MaxXx1313 2012-07-23 12:33:34

+0

還有一個!您可以爲前N個元素設置另一個項目渲染器,而不僅僅是一個 – MaxXx1313 2012-07-23 12:35:31

相關問題