5 Replies Latest reply on Jul 10, 2009 3:43 PM by meshgraphics

    Sizing Tile to its children?

    msakrejda Level 4

      When I add a number of children to a Tile without putting size constraints on the Tile itself, the Tile resizes itself in a more-or-less sensible fashion. However, what I would like to do is set the Tile to be 100% width, and have it adapt its height to be just large enough to hold all its children in this layout.

       

      I have not worked much with the sizing / layout portion of extending components--is this sort of layout possible? Essentially, I'd like Tile to resize itself to its children like HBox and VBox do. Can someone point me in the right direction?

       

      Thanks,

      Maciek

        • 1. Re: Sizing Tile to its children?
          msakrejda Level 4

          So apparently, this works fine when the width of the Tile is set explicitly, but I need to be able to use a percentWidth instead. I imagine the problem stems from the way that percent widths are resolved. Is there a sensible way to ammend this behavior?

          • 2. Re: Sizing Tile to its children?
            meshgraphics Level 2

            I don't get it.

            • 3. Re: Sizing Tile to its children?
              msakrejda Level 4

              Sorry, I'll clarify:

               

              Suppose I have the following Tile:

               

              <?xml version="1.0" encoding="utf-8"?>
              <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="300" height="500">
                  <mx:Tile id="tile" width="300" horizontalGap="2" verticalGap="2" backgroundColor="green"
                      creationComplete="heightInfo.dataProvider=heights">
                      <mx:Canvas width="40" height="40" backgroundColor="red"/>
                      <mx:Canvas width="40" height="40" backgroundColor="red"/>
                      <mx:Canvas width="40" height="40" backgroundColor="red"/>
                      <mx:Canvas width="40" height="40" backgroundColor="red"/>
                      <mx:Canvas width="40" height="40" backgroundColor="red"/>
                      <mx:Canvas width="40" height="40" backgroundColor="red"/>
                      <mx:Canvas width="40" height="40" backgroundColor="red"/>
                      <mx:Canvas width="40" height="40" backgroundColor="red"/>
                      <mx:Canvas width="40" height="40" backgroundColor="red"/>
                  </mx:Tile>

              </mv:VBox>

               

              This lays all its children out nicely, and the Tile is 82 (40 + 40 +  2) pixels tall to give enough space for the two rows and no more. However, when I change the width to be "100%" (instead of the explicit 300 that is the same as its parent container), the default height is guesstimated (looking at the docs, it uses the square root of the total number of children to make the guess). This is reasonable, but in this case (and possibly many others I'm dealing with, since I'm generating the children dynamically and don't know how many there will be up front), I have an extra row left over. Essentially, once the final width is determined, I'd like the Tile to adjust its height (just as it does when an explicit width is specified).

              • 4. Re: Sizing Tile to its children?
                meshgraphics Level 2

                I made the tile 100% and played with size of outer vbox.  The tile background will look irregular at different sizes.

                 

                If you want perfection, you will have to dig into the Tile control or create a new class that acts like it.

                 

                • 5. Re: Sizing Tile to its children?
                  msakrejda Level 4

                  >If you want perfection, you will have to dig into the Tile control or create a new class that acts like it.

                   

                  That's more or less what I'm trying to do. I don't really need perfection: I just need the Tile to size its height according to the number of children after it has figured out its actual width from its percent width. I was looking for help in how to accomplish this--which Tile method to override so I can set its size. This is *not* in a performance sensitive spot, so I don't really mind if it's inefficient. I just have no reliable way to accomplish this now.