处理自动添加滚动条
我有这样的问题:我正在创建一个容器,它的内容在运行时。这是一个粗略的结构:
--VBox
----Form
-------FormItem
...
-------FormItem
----ControlBar
我已经修复了表单的 maxHeights 容器以将其保持在屏幕范围内。但是当我得到垂直滚动条时,水平滚动条也会出现(似乎没有足够的地方放置此 VScrollBar)。
为了避免这个问题,我为水平滚动的出现创建了一个监听器,所以如果它出现,我会稍微增加容器,这样它就会正常地支撑另一个滚动条:
form.addEventListener(Event.ADDED, function(event:Event):void{
if(event.target is HScrollBar){
while(form.horizontalScrollBar && form.horizontalScrollBar.visible && !(form.width > form.maxWidth)){
form.width += 10;
form.validateDisplayList();
}
}
});
我也尝试过 validateNow
和其他类似的方法。我这里有什么: 1. 正在添加HScrollBar
。 2. 我们增加一点容器的宽度,所以它消失了。 3. 当它消失时,验证在尝试测量不存在的滚动条时会抛出空指针异常。我还尝试在验证之前添加 validateProperties ,但它也不起作用。
任何人都可以帮助摆脱这个烦人的卷轴吗? :)
I have such problem: I'm creating a container and it's content at runtime. Here's a rough structure:
--VBox
----Form
-------FormItem
...
-------FormItem
----ControlBar
I have fixed maxHeights for the form
container to keep it in bounds of screen. But when I get vertical scrollbar, the horisontal also appears (seems like it's not enough place for this VScrollBar).
To escape this problem, I've created a listener for horisontal scroll appearing, so if it appears, I'll increase container a bit, so it would feet the other scrollbar normally:
form.addEventListener(Event.ADDED, function(event:Event):void{
if(event.target is HScrollBar){
while(form.horizontalScrollBar && form.horizontalScrollBar.visible && !(form.width > form.maxWidth)){
form.width += 10;
form.validateDisplayList();
}
}
});
I've tried also validateNow
and other similar methods. What I have here:
1. The HScrollBar
is being added.
2. We increase a bit the width of container, so it disappears.
3. When it disappears, the validating throws the null-pointer exception when it tries to measure the non-existing scrollbar. I've also tried to add validateProperties
before validation, but it didn't worked either.
Can anyone help to get rid of this annoying scroll? :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是 - 如果您的scrollPolicy设置为
auto
Flex在计算布局时不会考虑滚动尺寸。因此,当滚动出现时,它会显示在已经存在的内容上。当内容被滚动隐藏时,会出现水平滚动,因此可以通过滚动访问所有内容。我通常处理这个问题的方法是始终将paddingRight
(或当父级为Canvas
时right
)样式属性设置为 20(滚动通常宽度为16) 所以当滚动出现时它不会重叠任何东西。The problem is - if your scrollPolicy is set to
auto
Flex does not take scroll dimensions into consideration while calculating layout. So when scroll appears it is displayed over the content that it's already there. And when the content is hidden by the scroll a horizontal scroll appears so all content can be accessed via scrolling. The way I usually deal with that is to always setpaddingRight
(orright
when parent isCanvas
) style property to 20 (scroll usual width is 16) so when the scroll appears it doesn't overlap anything.