使用 FB4,我想更改开放火花 DropDownList 的高度。默认情况下,它在滚动前最多显示 6 个项目。我的下拉列表包含 7 个项目,所以我想更改打开下拉列表的高度以适应所有 7 个项目而无需滚动。作为一种解决方法,我更改了项目的字体大小,使它们更小并且全部适合 7,但较小的字体看起来不太好。有没有办法改变这个高度?我对 Flash 比较陌生,所以如果它是一个复杂的解决方案,请详细说明:-)。
5 回答
Isn't it easier if you use the property requestedRowCount of the verticalLayout?
<s:DropDownList dataProvider="{myDataProvider}">
<s:layout>
<s:VerticalLayout requestedRowCount="10"/>
</s:layout>
</s:DropDownList>
问题是,在 Flex 4 中,DropDownListSkin 已maxHeight="134"
为您可能正在使用的默认皮肤定义。如果对象超出该高度,则强制显示滚动条。您需要做的就是将他们的 DropDownListSkin 代码复制/粘贴到自定义皮肤中,然后通过 CSS 将其应用于您的 DropDownList:
VariableHeightDropDownListSkin
<?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"
alpha.disabled=".5">
<!-- host component -->
<fx:Metadata>
<![CDATA[
/**
* @copy spark.skins.spark.ApplicationSkin#hostComponent
*/
[HostComponent("spark.components.DropDownList")]
]]>
</fx:Metadata>
<s:states>
<s:State name="normal" />
<s:State name="open" />
<s:State name="disabled" />
</s:states>
<s:PopUpAnchor id="popUp" displayPopUp.normal="false" displayPopUp.open="true" includeIn="open"
left="0" right="0" top="0" bottom="0" itemDestructionPolicy="auto"
popUpPosition="below" popUpWidthMatchesAnchorWidth="true">
<!-- removed maxHeight! -->
<s:Group id="dropDown" minHeight="22">
<!-- border/fill -->
<s:Rect left="0" right="0" top="0" bottom="0">
<s:stroke>
<s:SolidColorStroke color="0x5380D0" />
</s:stroke>
<s:fill>
<s:SolidColor color="0xFFFFFF" />
</s:fill>
</s:Rect>
<s:Scroller left="0" top="0" right="0" bottom="0" focusEnabled="false" minViewportInset="1">
<s:DataGroup id="dataGroup" itemRenderer="spark.skins.spark.DefaultItemRenderer">
<s:layout>
<s:VerticalLayout gap="0" horizontalAlign="contentJustify"/>
</s:layout>
</s:DataGroup>
</s:Scroller>
<s:filters>
<s:DropShadowFilter blurX="20" blurY="20" distance="7" angle="90" alpha="0.45" color="0x6087CC" />
</s:filters>
</s:Group>
</s:PopUpAnchor>
<s:Button id="openButton" left="0" right="0" top="0" bottom="0" focusEnabled="false"
skinClass="spark.skins.spark.DropDownListButtonSkin" />
<s:Label id="labelDisplay" verticalAlign="middle" lineBreak="explicit"
mouseEnabled="false" mouseChildren="false"
left="7" right="30" top="2" bottom="2" width="75" verticalCenter="1" />
</s:Skin>
示例应用程序
<?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">
<fx:Style>
@namespace mx "library://ns.adobe.com/flex/mx";
@namespace s "library://ns.adobe.com/flex/spark";
s|DropDownList
{
skinClass: ClassReference("VariableHeightDropDownListSkin");
}
</fx:Style>
<s:DropDownList labelField="name" horizontalCenter="0" verticalCenter="0">
<s:layout>
<s:VerticalLayout requestedRowCount="7"/>
</s:layout>
<s:dataProvider>
<mx:ArrayCollection>
<fx:Object name="one"/>
<fx:Object name="two"/>
<fx:Object name="three"/>
<fx:Object name="four"/>
<fx:Object name="five"/>
<fx:Object name="six"/>
<fx:Object name="seven"/>
</mx:ArrayCollection>
</s:dataProvider>
</s:DropDownList>
</s:Application>
让我知道这是否有帮助,兰斯
viatropos 答案会起作用,但是您应该尽量避免覆盖整个皮肤。
在这种情况下,您会注意到在 viatropos 的 VariableHeightDropDownListSkin 代码中,他删除了 maxHeight 属性的 Group 还指定了一个“id”。
现在查看 DropDownList 的文档,您会在 SkinParts 部分注意到有一个“dropDown”皮肤部件。这实际上是 DropDownList 的一个属性。
因此,您可以简单地使用动作脚本,而不是覆盖皮肤(我在这里使用 UIComponent.DEFAULT_MAX_HEIGHT,但您可以随意使用):
(MyDropDownList.dropDown as UIComponent).maxHeight = UIComponent.DEFAULT_MAX_HEIGHT;
Unfortunately, this is a lot more complicated in Flex 4 than it was in Flex 3:
You should be able to define a layout for the DropDownList with a higher requestedRowCount
(details here), but for > 6 rows you need to do more work (Flex issue SDK-25364).
在 FB3 中,它的 rowCount 导致下拉列表是列表控件的后代。FB4 可能类似。
myDropdown.rowCount = 7;
我通常使用更像
myDropdown.rowCount = myDataProvider.lenght();