2011-10-31 38 views
0

如何在Flex 4.5中创建一个组件(使用它为android ..),该组件具有textInput并在其右侧有一个按钮,以便该按钮具有固定大小,并且textInput展开填充组件父项的剩余空间?make textEdit在Flex 4.5中填充宽度

这是组件..

<s:HGroup> 
    <s:TextInput width="????"/> 
    <s:Button width="37" height="37" /> 
</s:HGroup> 
当然,我不知道要放什么东西宽度。我也应该指定HGroup宽度的

+0

如果我把100%溢出屏幕的宽度.. – luca

回答

0
<s:HGroup width="100%"> 
    <s:TextInput width="width" /> 
    <s:Button width="37" /> 
</s:Group> 

这里

width = [[android screen width (or group width) - 37 ]/android screen width (or group width) ] * 100 

其比例..

或尝试两种设置100% ..这也许问题。

编辑:

只是让你的屏幕尺寸在您的应用程序。这里是链接到的问题.. How to get screen dimensionshere

+0

抱歉,但我不明白..我怎么能设置为100%?这失败了目的..和基于百分比的人没有任何意义,如果屏幕更改大小(它的确) – luca

+0

你可以得到屏幕尺寸的大小在你的应用程序..检查我的编辑。 – Hadi

0

试试这个:

<fx:Script> 

     <![CDATA[ 
     import spark.components.Button; 

     private function onCreate():void 
     { 
     var yourButton:Button = new Button(); 
     yourButton.width = 37; 
     yourButton.x = 10; 
     yourButton.y = 100; 
     text.addChild(yourButton); 
     } 
]]> 
    </fx:Script> 

    <s:TextInput borderVisible="true" id="text" height="100%" width="100%" creationComplete="onCreate()" /> 
0

套装HGroupTextInput的宽度都设为100%。

如果您没有在HGroup上指定100%的宽度,那么它将被给予默认的静态宽度,该宽度可能比屏幕的宽度更宽。

<s:HGroup width="100%"> 
    <s:TextInput width="100%" /> 
    <s:Button width="37" height="37" /> 
</s:HGroup> 
+0

我曾试过这个,它没有工作..任何想法为什么?可能的原因? – luca

+0

确保从您的'TextInput'到您的'Application'的所有容器(和父容器)具有指定的宽度 - 任何没有指定宽度的容器将被设置为它们的默认大小,并且将防止儿童正确调整大小。 –

0

Flex根据孩子的父母确定相对大小。

如果你没有给父母组一个宽度,那么TextInput不知道它应该填充到100%。

<s:HGroup width="100%"> 
    <s:TextInput width="100%"/> 
    <s:Button width="37" height="37" /> 
</s:HGroup> 

作为回应“设置它们都为100%”答案的一个附注。 Flex将允许您将多个百分比宽度设置为100%。 2将最终被同等权重。 SO

<s:HGroup width="100%"> 
    <s:TextInput width="100%"/> 
    <s:Button width="100%"/> 
</s:HGroup> 

将导致2个组件都占据屏幕的一半。

<s:HGroup width="100%"> 
    <s:TextInput width="200%"/> 
    <s:Button width="100%"/> 
</s:HGroup> 

会导致一个TextInput是两倍宽按钮

如果你想设置从Actionscript中百分比计算的高度和宽度,而不是MXML你需要说textInput.percentWidth = 100;