1、创建自定义项目渲染器
<s:List id="list" dataProvider="{provider}" selectedIndex="0">
<s:itemRenderer>
<fx:Component>
<s:ItemRenderer>
<s:states>
<s:State name="normal"/>
<s:State name="hovered"/>
<s:State name="selected"/>
</s:states>
<s:Label text="{data}"/>
</s:ItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:List>
项目呈现器的基本状态为“normal”、“hovered”和“selected”。在 Flex 4.5 中,添加了“down”和“downAndSelected”。
2、在List中滚动到指定项目
spark.components.List.ensureIndexIsVisible(index:int):void
滚动数据项以使其可见的简便处理方法。如果指定索引的数据项未完全显示,List 将滚动,直到数据项显示出来。如果数据项已显示出来,则不会发生任何其他滚动。
4、更改List的布局
(1)使用自定义皮肤
<?xml version="1.0" encoding="utf-8"?>
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<!-- host component -->
<fx:Metadata>
[HostComponent("spark.components.List")]
</fx:Metadata>
<!-- states -->
<s:states>
<s:State name="disabled" />
<s:State name="normal" />
<s:State name="selected" />
</s:states>
<s:Scroller>
<s:DataGroup id="dataGroup" height="{hostComponent.height}" width="{hostComponent.width}">
<s:layout>
<s:TileLayout clipAndEnableScrolling="true"/>
</s:layout>
</s:DataGroup>
</s:Scroller>
</s:Skin>
(2)上面是cookbook中得例子,也可以直接用layout
<s:List width="120" height="80" dataProvider="{provider}" selectedIndex="0"
itemRenderer="spark.skins.spark.DefaultItemRenderer">
<s:layout>
<s:TileLayout clipAndEnableScrolling="true"/>
</s:layout>
</s:List>
7、设置特定的可选项
SelectionRestrictedRenderer.mxml
<?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/halo">
<fx:Script>
<![CDATA[
private var __fun:Function;
public function set selectableFunction(fun:Function):void {
__fun = fun;
}
override public function set data(value:Object):void {
if (value && __fun(value)) {
mouseEnabled = true;
enabled = true;
} else {
mouseEnabled = false;
enabled = false;
}
super.data = value;
}
]]>
</fx:Script>
<s:states>
<s:State name="normal"/>
<s:State name="hovered"/>
<s:State name="selected"/>
</s:states>
<s:Label text="{data}"/>
</s:ItemRenderer>
<?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/halo"
creationComplete="init()">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import renderers.SelectionRestrictedRenderer;
[Bindable]
public var provider:ArrayCollection;
public function init():void {
provider = new ArrayCollection([12, 13, 4, 5, 16, 19, 400]);
}
public function customItemRendererFunction(item:*):IFactory {
var factory:ClassFactory = new ClassFactory(SelectionRestrictedRenderer);
factory.properties = {"selectableFunction": selectionAllowFunction};
return factory;
}
public function selectionAllowFunction(value:*):Boolean {
if (value < Number(textInput.text)) {
return false;
} else {
return true;
}
}
public function updateList():void {
list.executeBindings();
}
]]>
</fx:Script>
<s:layout>
<s:HorizontalLayout/>
</s:layout>
<s:TextInput id="textInput" change="updateList()"/>
<s:List id="list" dataProvider="{provider}" itemRendererFunction="{customItemRendererFunction}"/>
</s:Application>
9、为List添加右键菜单
在ItemRenderer的set data()方法中
var personMenu:ContextMenu = new ContextMenu();
var lookupRecord:ContextMenuItem = new
ContextMenuItem("Look Up Record");
var lookupPicture:ContextMenuItem = new
ContextMenuItem("Look Up Picture");
personMenu.customItems.push(lookupRecord);
personMenu.customItems.push(lookupPicture);
this.contextMenu = personMenu;
public function ContextMenuItem(caption:String, separatorBefore:Boolean = false, enabled:Boolean = true, visible:Boolean = true)
caption:String — 指定与菜单项关联的文本。有关 caption 值限制,请参阅 ContextMenuItem 类概述。
separatorBefore:Boolean (default = false) — 指定分隔条是否显示在上下文菜单中的菜单项上方。默认值为 false。
enabled:Boolean (default = true) — 指定菜单项在上下文菜单中是处于启用状态还是禁用状态。默认值为 true(启用)。此参数是可选的。
visible:Boolean (default = true) — 指定菜单项是否可见。默认值为 true(可见)。
分享到:
相关推荐
Flex_CookBook_读书笔记(精品) Flex_CookBook_读书笔记(精品)
ActionScript3.0 Cookbook 学习笔记
PHP Cookbook读书笔记 &ndash; 第15章创建Web服务.docx
Apache Solr 4 Cookbook Apache Solr 4 Cookbook Apache Solr 4 Cookbook Apache Solr 4 Cookbook Apache Solr 4 Cookbook
flex4 cookbook4 flex4 cookbook4不可多得的一本好书
介绍skip list实现的文档
Flex 4 Cookbook
Cinema 4D R14 Cookbook
iOS 4 Programming Cookbook iphone ipad 需要ios4的编程书籍的朋友可以看看这个
Microsoft.Windows.Workflow.Foundation.4.0.Cookbook 中文翻译
Swift 4 Programming Cookbook
Redis 4.x Cookbook中文版,2018年5月出版,仅供学习和参考。
大家看看哈,希望大家相互学习,这是小弟朋友给我的,现在共享给大家
O'Reilly《C# 6.0 Cookbook 4th Edition》《C#经典实例第4版 英文版》及代码
Unreal Engine 4 Scripting with C++Cookbook Get the best out of your games by scripting them using UE4 William Sherif Stephen Whittle 2016版
Redis 4.x cookbook
ARM Cortex M4 Cookbook,Over 50 hands-on recipes that will help you develop amazing real-time applications using GPIO, RS232, ADC, DAC, timers, audio codecs, graphics LCD, and a touch screen
Lucene 4 Cookbook is a practical guide that shows you how to build a scalable search engine for your application, from an internal documentation search to a wide-scale web implementation with millions...
Swift 4 Programming Cookbook 英文azw3 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
Flex4 Cookbook 最新英文原版(全)