Detecting if UIComponent has scroll bars active

2019-06-11 15:06发布

I have a TileList in flex, and need to be able to detect if the scroll bars are shown or not, so I can change the size of the items it is laying out.

ScrollPolicy is set to auto, but I need a variable like CurrentScrollPolicy which will change from off to on depending on the content.

Thanks

4条回答
我只想做你的唯一
2楼-- · 2019-06-11 15:50

Thanks eBuildy, your right!

I have created an example that also takes into account the fact that scroll bars get hidden when not needed rather than set back to null:

   public class CustomTileList extends TileList
{

    public function CustomTileList()
    {
        super();
    }

    /**
     * Returns true if the vertical scroll bar is displayed
     * @return Boolean
     *
     */
    public function hasVerticalScrollBar():Boolean
    {
        if (super.verticalScrollBar == null || super.verticalScrollBar.visible == false)
            return false;
        return true;
    }

}

Thanks for the help.

查看更多
做个烂人
3楼-- · 2019-06-11 15:52

You need to check the verticalScrollBar. If its null then there is no scrollbar. If it is not null then there is a scrollbar.

查看更多
Summer. ? 凉城
4楼-- · 2019-06-11 16:04

I used really simple trick to get around this issue. Set the scroll position to the maximum since it will always be zero when there are no scroll bars if you check it and it is above zero add hight to the element because there must be scroll bars.

yourControl.verticalScrollPosition = yourConrol.maxVerticalScrollPosition;

for (var i:int=0; i <= yourControl.verticalScrollPosition ;i++)
{
     yourControl.height = yourControl.height+16;
}
查看更多
Melony?
5楼-- · 2019-06-11 16:11

Or, in case you don't want to override the list, you could have something like

if(listInstance.mx_internal::scroll_verticalScrollBar != null){...}

Cheers!

查看更多
登录 后发表回答