HBox自适应宽度问题

xiewneqi 2010-12-09 02:48:19
1、问题场景:
页面中有一HBox,将其宽度设置为父容器宽度的百比分时(如80%),如果HBox内的子元素非常多,超过了HBox的宽度,此时HBox无法保持基于父容器百分比的宽度,而会自动变宽。这种情形下,要如何处理,才能保证无论HBox中的元素有多少,总能使HBox的宽度保持预定义的百分比?
2、代码描述:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script>
<![CDATA[
[Bindable]
private var dp:Array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36];

]]>
</mx:Script>
<mx:HBox id="hbox" width="30%" height="35" backgroundColor="white">
<mx:Repeater id="rp" dataProvider="{dp}">
<mx:Label text="{String(rp.currentItem)}"/>
</mx:Repeater>
</mx:HBox>
</mx:Application>

3、截图描述:

以上是上述代码显示结果,显然HBox的宽度已经超过了页面的30%。
...全文
468 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
passself 2010-12-10
  • 打赏
  • 举报
回复
maxWidth="{childID.width}就可以了,childID是最宽的那个标签的宽度
touchmps 2010-12-09
  • 打赏
  • 举报
回复
没有那么复杂,把 width="30%"替换为 maxWidth="{this.width*0.3}"
fw176170847 2010-12-09
  • 打赏
  • 举报
回复
package
{
import mx.containers.HBox;

public class FwHbox extends HBox
{
public function FwHbox()
{
super();
}

override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
}

override protected function measure():void
{
// super.measure();
}

}
}
leemiki 2010-12-09
  • 打赏
  • 举报
回复
%其实就是Application尺寸的百分比

所以你可以直接在代码中控制

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" initialize="init()">
<mx:Script>
<![CDATA[
[Bindable]
private var dp:Array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36];

private function init():void{
hbox.width = Application.application.width*0.3;
}
]]>
</mx:Script>
<mx:HBox id="hbox" height="35" backgroundColor="white">
<mx:Repeater id="rp" dataProvider="{dp}">
<mx:Label text="{String(rp.currentItem)}"/>
</mx:Repeater>
</mx:HBox>
</mx:Application>

4,328

社区成员

发帖
与我相关
我的任务
社区描述
多媒体/设计 Flex
社区管理员
  • Flex
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧