flex4.0 利用外部项呈示器显示List信息并添加图片示例
作者:
利用外部项呈示器显示List信息并添加图片,在本文有个不错的示例,喜欢的朋友可以参考下,希望对大家有所帮助
首先是外部项呈示器文件:
<?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 id="stuList" width="100%" height="100%" dataProvider="{stuColl}" itemRenderer="com.hz.StuListItemRender">
</s:List>
显示效果如下:
复制代码 代码如下:
<?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 id="stuList" width="100%" height="100%" dataProvider="{stuColl}" itemRenderer="com.hz.StuListItemRender">
</s:List>
显示效果如下: