首先是外部项呈示器文件:
复制代码 代码如下:
<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
autoDrawBackground="true">
<s:Group>
<s:layout>
<s:HorizontalLayout paddingLeft="10" paddingTop="10" gap="20" verticalAlign="middle"/>
</s:layout>
<fx:Script>
<![CDATA[
[Embed(source="images/user_superman.png")]
private const imgsource:Class;
private function getImage(data:Object):Object
{
if(data!=null)
{
var img:Image=new Image();
img.source=imgsource;
this.addElement(img);
}
return null;
}
]]>
</fx:Script>
<s:Image source="{getImage(this.data)}"/>
<s:Label text="{data.sName}+'***'+{data.sAge}"/>
</s:Group>
</s:ItemRenderer>
第二部呢,就是在application主文件中引用即可:
复制代码 代码如下:
<s:List dataProvider="{stuColl}" itemRenderer="com.hz.StuListItemRender">
</s:List>
显示效果如下: