处理自动添加滚动条

发布于 2024-09-18 06:33:59 字数 863 浏览 5 评论 0原文

我有这样的问题:我正在创建一个容器,它的内容在运行时。这是一个粗略的结构:

--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 validateNowand 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

驱逐舰岛风号 2024-09-25 06:33:59

问题是 - 如果您的scrollPolicy设置为auto Flex在计算布局时不会考虑滚动尺寸。因此,当滚动出现时,它会显示在已经存在的内容上。当内容被滚动隐藏时,会出现水平滚动,因此可以通过滚动访问所有内容。我通常处理这个问题的方法是始终将 paddingRight (或当父级为 Canvasright)样式属性设置为 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 set paddingRight (or right when parent is Canvas) style property to 20 (scroll usual width is 16) so when the scroll appears it doesn't overlap anything.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文