我有一个带有自定义ItemRenderer(IR)的TileList。 IR可以是TextInput,TextArea或ComboBox。如果在一行中有一个TextArea,我希望这行比其他行具有更高的高度。毕竟,所有的行都必须具有相同的高度,我不在乎。我关心的是,如果我有一个没有TextArea的表单,我希望行高是最低的。TileList中的行的Flex可变高度
经过一番工作,我实现了以下代码。但是,正如你将在封闭的屏幕上欣赏,我没有达到我想要的。第一次输入表单时,它看起来不对,但第二次输入时,它看起来没问题。但是,如果你进入另一个不同领域的表格,然后重新打开刚刚打开的表格,它又会出现错误。当它看起来不对,似乎每一行都有标准的高度。
我失踪了什么?我应该以某种方式定制TileList吗?我是否已将invalidateDisplayList和invalidateSize放在错误的地方?
表1案例错:
http://flic.kr/p/bfJSUM
表1案例OK:
http://flic.kr/p/bfJSQT
表2案例错:
http://flic.kr/p/bfJSSn
表2案例确定:
http://flic.kr/p/bfJUwe
的TileList:
<mx:VBox id="camposextras" visible="true" verticalGap="0" horizontalGap="0" width="100%" height="100%" >
<mx:TileList wordWrap="true" variableRowHeight="true" width="100%" textAlign="left" columnCount="2" dataProvider="{model.specialfield_issue_list}" itemRenderer="org.nevis.cairngorm.mod.view.IRCampoEspecial" direction="horizontal">
</mx:TileList>
</mx:VBox>
的ItemRenderer:
<?xml version="1.0"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
horizontalAlign="left" verticalAlign="middle"
verticalGap="0" borderStyle="none" width="100%"
horizontalScrollPolicy="off" verticalScrollPolicy="off"
>
<mx:Script>
<![CDATA[
import mx.controls.TextArea;
import mx.controls.Text;
import org.nevis.cairngorm.mod.model.ModelLocator;
import mx.core.UIComponent;
import mx.controls.Label;
import mx.controls.ComboBox;
import mx.controls.TextInput;
import utils.Utils;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
[Bindable]
public var model:ModelLocator=ModelLocator.getInstance();
[Bindable]
private var fieldLabelVisible:Boolean = false;
[Bindable]
private var textInputVisible:Boolean = false;
[Bindable]
private var textAreaVisible:Boolean = false;
[Bindable]
private var comboBoxVisible:Boolean = false;
[Bindable]
private var mandatoryLabelVisible:Boolean = false;
[Bindable]
private var _contenedorHeight:int = 25;
public function updata_valor_text(valor:Event):void {
data.value=valor.currentTarget.text;
}
public function updata_valor_combo(valor:Event):void {
data.value=valor.currentTarget.selectedItem.valuesspecialfieldid
}
/**
* Make sure IR has real variable height for rows
*/
override public function get height():Number {
//Make sure variableRowHeight is set to true in the container of this IR
return _contenedorHeight;
}
override public function set height(value:Number):void {
_contenedorHeight = value;
}
override public function set data(value:Object):void {
var i:int;
var sel:int;
super.data = value;
callLater(function onceAllCreated():void{
if (value){
_contenedorHeight = 25; //Default value
fieldLabelVisible = true;
lb.text=value.spe_name;
lb.toolTip=value.spe_description;
lb.width=150;
lb.name='etiqueta';
lb.styleName='texto-iza';
switch (value.type){
case "text":
if(value.spe_max<=40) {
ti.text=value.value;
ti.name='texto';
ti.maxChars=value.spe_max;
if(value.spe_max<=20) {
ti.width=150;
} else {
ti.width=300;
}
textInputVisible = true;
} else {
ta.text=value.value;
ta.name='texto';
ta.maxChars=value.spe_max;
ta.width=300;
textAreaVisible = true;
_contenedorHeight = 60;
}
break;
case "select":
cb.labelField='val_value';
cb.name='seleccionable';
cb.width=150;
comboBoxVisible = true;
break;
default:break;
}
if (value.spe_mandatory==1){
mandatory.text="*";
mandatory.toolTip="Mandatory";
mandatory.width=10;
mandatory.name='mandatory';
mandatory.styleName='texto-iza';
mandatoryLabelVisible = true;
}
} else {
fieldLabelVisible = false;
textInputVisible = false;
textAreaVisible = false;
comboBoxVisible = false;
mandatoryLabelVisible = false;
}
invalidateDisplayList();
invalidateSize();
});
}
]]>
</mx:Script>
<mx:HBox id="contenedor" toolTip="{data.spe_description}" verticalAlign="middle" horizontalAlign="left" width="100%" height="{_contenedorHeight}">
<mx:Label id="lb" visible="{fieldLabelVisible}" includeInLayout="{fieldLabelVisible}"/>
<mx:TextInput id="ti" visible="{textInputVisible}" includeInLayout="{textInputVisible}" change="updata_valor_text(event)"/>
<mx:TextArea id="ta" visible="{textAreaVisible}" includeInLayout="{textAreaVisible}" height="50" change="updata_valor_text(event)"/>
<mx:ComboBox id="cb" visible="{comboBoxVisible}" includeInLayout="{comboBoxVisible}" change="updata_valor_combo(event)"/>
<mx:Label id="mandatory" visible="{mandatoryLabelVisible}" includeInLayout="{mandatoryLabelVisible}"/>
</mx:HBox>
</mx:VBox>
注:这是一个旧的应用程序和它的完成w^ith Flex 2 SDK 2.0.1修补程序3.
感谢您的帮助!
我曾尝试minHeight =“25”,但结果仍然相同。 – Roger
那么,我找到了解决方案。在项目渲染器中,我已经把所有这三个属性:minHeight =“25”maxHeight =“60”height =“60”另外,我已经删除了对invalidateDisplayList和invalidateSize的调用,因为它们不是必需的。非常感谢!!! – Roger
我说得太早。我刚刚解决的是,第一次进入表格时一切正常。然而,当你去另一个表单与不同的领域,你重新打开以前,表单再次出错... – Roger