要求是我需要文本旁边的文本输入(多行文字)。通常我做的是,我已经取得了文本的宽度并调整了textinput的x和y位置,因此它将被放置在文本旁边
EX:sample text aaaaa <TextInput>
。
但是如果文本是多行的,那么textinput应该放在文本的末尾,而不仅仅是文本旁边。
EX:
sample textaaaaaaaaaaaaa
aaaa bbb <textinput>
但我得到的输出如下
sample textaaaaaaaaaaaaa <textinput>
aaaa bbb
有没有人有任何建议。
以下是代码
MemoStepLabelBox.as
package {
import mx.controls.Label;
import mx.controls.Text;
import mx.controls.TextInput;
import mx.core.Container;
public class MemoStepLabelBox extends Container
{
public function MemoStepLabelBox()
{
super();
}
public var textLabel:Text;
public var input:TextInput;
override protected function createChildren():void
{
super.createChildren();
addChild(textLabel);
if (spacer)
{
addChild(spacer);
}
if (input)
{
addChild(input);
}
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
var labelWidth:Number = textLabel.getExplicitOrMeasuredWidth();
var requiredWidth:Number = labelWidth;
if (input)
{
input.setActualSize(input.getExplicitOrMeasuredWidth(), input.getExplicitOrMeasuredHeight());
requiredWidth += input.width;
}
if (unscaledWidth)
{
textLabel.setActualSize(labelWidth, textLabel.getExplicitOrMeasuredHeight());
textLabel.move(0, (unscaledHeight - textLabel.height) / 2);
currentX = textLabel.x + textLabel.width;
if (input)
{
input.move(currentX, (unscaledHeight - input.height) / 2);
currentX = input.x + input.width;
}
}
}
}
}
main.mxml
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:local="*" creationComplete="stack.selectedIndex = 0;">
<mx:Button label="Insert Steps" width="100" click="onInsertStepsClick()"/>-->
<local:MemoStepLabelBox id="hbxHasInput" width="100%">
<local:textLabel>
<mx:Text id="txtStep" width="100%"
text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaa" />
</local:textLabel>
<local:spacer>
<mx:Spacer id="hasInputSpacer" width="6" themeColor="green" />
</local:spacer>
<local:input>
<mx:TextInput id="txtIn" width="100" paddingTop="0"
paddingBottom="0" />
</local:input>
</local:MemoStepLabelBox>
</mx:Application>