Flex布局小练--博文列表item布局实现
<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:layout>
<s:VerticalLayout paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10" gap="0"/>
</s:layout>
<fx:Script>
<![CDATA[
import mx.core.FlexGlobals;
import spark.components.RichText;
[Bindable]
public var titleStyle:String = "bold";
[Bindable]
public var contentStyle:String;
protected function title_creationCompleteHandler(event:FlexEvent):void
{
title.setStyle("fontSize", "14");
title.setStyle("color", "0x333333");
title.setStyle("textAlign", "left");
title.setStyle("fontWeight", titleStyle);
}
protected function content_creationCompleteHandler(event:FlexEvent):void
{
content.setStyle("fontSize", "12");
content.setStyle("color", "0x666666");
content.setStyle("textAlign", "left");
content.setStyle("fontWeight", contentStyle);
}
]]>
</fx:Script>
<s:Group width="100%" height="100%">
<s:layout>
<s:HorizontalLayout paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10" gap="10"/>
</s:layout>
<s:VGroup width="100%" height="100%">
<s:RichText id="title" text="{data.title}" creationComplete="title_creationCompleteHandler(event)"/>
<s:RichText id="content" text="{data.content}" creationComplete="content_creationCompleteHandler(event)"/>
</s:VGroup>
<s:Image source="{data.authorImage}" width="50" height="50"/>
</s:Group>
</s:ItemRenderer>
这段代码使用了Flex的ItemRenderer来定义博文列表中每个博文的布局。它使用了<s:layout>
标签来指定容器内部组件的布局方式,并通过creationComplete
事件在运行时动态设置了标题和内容的样式。这样的实现方式使得布局和样式的定义更加灵活和高效。
评论已关闭