【问题标题】:Controlling which VBox gets the scrollbar控制哪个 VBox 获取滚动条
【发布时间】:2009-11-04 16:01:13
【问题描述】:

我有以下应用程序,我试图在 TabNavigator 内的某处放置一个滚动条,最好是在最里面的 Vbox 上,但滚动条总是在面板上结束。是否有某种属性可以控制这一点?我以为 height=100% 会控制它,但它似乎不起作用。

样品在这里。你可以在上面查看源码: VBox Sample

这里是源代码:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" viewSourceURL="srcview/index.html">
    <mx:Panel width="400" height="400">
        <mx:TabNavigator width="100%" height="100%" creationPolicy="all">
            <mx:VBox label="Tab 1" width="100%" height="100%">
                <mx:ViewStack width="100%" height="100%">
                    <mx:VBox width="100%" height="100%">
                        <mx:Text width="100%" height="500" text="This box is taller than the Panel, but the scrollbar is on the window." />
                    </mx:VBox>
                </mx:ViewStack>
            </mx:VBox>
        </mx:TabNavigator>    
    </mx:Panel>
</mx:Application>

【问题讨论】:

    标签: apache-flex flex3


    【解决方案1】:

    我发现正确的解决方案是将盒子上的 minheight 设置为 0。当 minheight 未定义时,盒子将尝试保持在测量的高度。通过设置 minheight,您可以告诉框可以缩小。

    【讨论】:

      【解决方案2】:

      我过去遇到过这个问题,解决方案有点不靠谱,但希望这会有所帮助:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
          <mx:Panel width="400" height="400" verticalScrollPolicy="off">
              <mx:TabNavigator width="100%" height="100%">
                  <mx:VBox id="container" label="Tab 1" width="100%" height="100%">
                       <mx:ViewStack width="100%" height="{container.height - 20}">
                          <mx:VBox width="100%" height="100%">
                              <mx:Text width="100%" height="500" text="This box is taller than the Panel, but the scrollbar is on the window." />
                          </mx:VBox>
                      </mx:ViewStack>
                  </mx:VBox>
              </mx:TabNavigator>    
          </mx:Panel>
      </mx:Application>
      

      Flex 似乎在大约 98% 的情况下都能正确计算动态组件尺寸,但有时我们需要“按摩”逻辑。

      当您查看您的布局层次结构(如上所示)时,您只需为数据绑定命名父容器(在本例中为 Tab1),然后使用该容器的高度属性来调整大小。 (您也不需要需要在面板上明确声明verticalScrollPolicy="off",但我使用if 来衡量:P)

      请注意,您可能需要从给定高度中减去一点,否则您的滚动条将低于组件边界;)

      【讨论】:

      • 对于一个非常令人发指的错误,这是一个非常天才的解决方案。不过,我不必从视图堆栈高度中减去 20。没有它渲染得很好。
      • 谢谢...这很好用。我也不需要 20px 偏移量......也许你需要它,因为你在“容器”或其他东西上有填充。
      • 我在 Linux 上使用 FB3 ......所以渲染可能对我来说有点偏离 ;) 很高兴它对你有用 :D
      • 我最近发现你所要做的就是在你想要的滚动条上设置一个 minHeight 。这告诉它可以小于它的内容。对我来说没有多大意义,但它有效。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多