前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Flex笔记_使用Spark列表控件 原

Flex笔记_使用Spark列表控件 原

作者头像
LeoXu
发布2018-08-15 14:34:39
5660
发布2018-08-15 14:34:39
举报
文章被收录于专栏:LeoXu的博客

ButtonBar

  • 创建ButtonBar时,可以使用任何实现了ICollectionView接口的对象作为dataProvider。
代码语言:javascript
复制
<?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:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<s:layout>
<s:VerticalLayout paddingLeft="20" paddingTop="20"/>
</s:layout>
<s:ButtonBar>
<s:ArrayCollection>
<fx:String>Button 1</fx:String>
<fx:String>Button 2</fx:String>
<fx:String>Button 3</fx:String>
<fx:String>Button 4</fx:String>
</s:ArrayCollection>
</s:ButtonBar>
</s:Application>

List

代码语言:javascript
复制
<?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:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<s:layout>
<s:VerticalLayout gap="1" useVirtualLayout="true"/>
</s:layout>
<s:List>
<s:dataProvider>
<s:ArrayCollection>
<fx:String>Item 1</fx:String>
<fx:String>Item 2</fx:String>
<fx:String>Item 3</fx:String>
<fx:String>Item 4</fx:String>
</s:ArrayCollection>
</s:dataProvider>
</s:List>
</s:Application>
代码语言:javascript
复制
<?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:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
<s:ArrayCollection id="listItems">
<fx:String>Item 1</fx:String>
<fx:String>Item 2</fx:String>
<fx:String>Item 3</fx:String>
<fx:String>Item 4</fx:String>
</s:ArrayCollection>
</fx:Declarations>
<s:layout>
<s:VerticalLayout gap="1" useVirtualLayout="true"/>
</s:layout>
<s:List dataProvider="{listItems}"/>
</s:Application>

DropDownList

代码语言:javascript
复制
<?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:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<s:layout>
<s:VerticalLayout paddingLeft="20" paddingTop="20"/>
</s:layout>
<s:DropDownList width="200" prompt="Please Select One">
<s:ArrayCollection>
<fx:String>Item 1</fx:String>
<fx:String>Item 2</fx:String>
<fx:String>Item 3</fx:String>
<fx:String>Item 4</fx:String>
</s:ArrayCollection>
</s:DropDownList>
</s:Application>

交互

  • 选择项目时默认分发事件:selectionChanged、itemFocusChanged、selectionChanging
  • IndexChangedEvent对象

类层次结构

ListBase ->  SkinnableDataContainer -> SkinnableContainerBase -> SkinnableComponent -> UIComponent ->

FlexSprite -> Sprite -> DisplayObjectContainer -> InteractiveObject -> DisplayObject ->

EventDispacher -> Object

构建基于List的自定义组件

构建自定义List组件

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
xmlns:s="library://ns.adobe.com/flex/spark" 
xmlns:mx="library://ns.adobe.com/flex/mx"
width="75%" height="75%"
horizontalCenter="0" verticalCenter="0">
<fx:Script>
<![CDATA[
import mx.events.IndexChangedEvent;
private function selectionChangingHandler(evt:IndexChangedEvent):void {
var item:* = list.dataProvider.getItemAt(evt.newIndex);
if(item.type != "travel"){
evt.preventDefault();
}
}
]]>
</fx:Script>
<s:VGroup left="20" right="20" top="20" bottom="20">
<s:Label text="Select a title to see the image."/>
<s:List id="list"
selectionChanging="selectionChangingHandler(event);"
width="100%" height="100%" lineHeight="22">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<s:itemRenderer>
<fx:Component>
<s:ItemRenderer>
<s:states>
<s:State name="normal" />
<s:State name="hovered" />
<s:State name="selected" />
</s:states>
<s:Rect left="0" right="0" top="0" bottom="0">
<s:fill>
<s:SolidColor color="0x999999" alpha="0"
 alpha.hovered="0.2" alpha.selected="0.4"/>
</s:fill>
</s:Rect>
<s:Label id="titleLabel" text="{data.title}"/>
<s:BitmapImage horizontalCenter="80" id="img" source="{data.image}" includeIn="selected"/>
</s:ItemRenderer>
</fx:Component>
</s:itemRenderer>
<s:dataProvider>
<s:ArrayList>
<fx:Object type="travel" title="Item 1" image="images/item1.jpg"/>
<fx:Object type="travel" title="Item 2" image="images/item2.jpg"/>
<fx:Object type="travel" title="Item 3" image="images/item3.jpg"/>
</s:ArrayList>
</s:dataProvider>
</s:List>
</s:VGroup>
</s:Group>
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2014/09/02 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • ButtonBar
  • List
  • DropDownList
  • 交互
  • 类层次结构
  • 构建基于List的自定义组件
    • 构建自定义List组件
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档