我是新手使用MXML进行构建应用程序的。

基本上,我正在使用瓷砖组构建瓷砖清单(其中6个)。当它在肖像视图上初始化时,它看起来很棒(第一行3,第二行3)。

但是,当我更改方向时,我希望瓷砖根据新的宽度和高度重新绘制。

从Stack Overflow中,我发现我可以收听调整大小事件。但是,我不知道如何将瓷砖组列入Redraw。

最初,我认为我可以将AutoLayout用于瓷砖组。但是,这没有解决问题。我很难寻找解决方案(也许我没有使用正确的关键词)。

我可以打电话给Redraw吗?

还是有其他方法可以使我的瓷砖响应方向?

这是我的代码:

<components:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
             xmlns:s="library://ns.adobe.com/flex/spark" xmlns:components="spark.components.*" 
             title="Forex Calculator">
<components:states>
    <s:State name="portrait"/>
    <s:State name="landscape"/>
</components:states>
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>

<s:TileGroup id="mainGroup" includeIn="portrait, landscape" autoLayout="true">
    <s:Rect width="75" height="75">
        <s:fill>
            <s:SolidColor color="0xd54f4f"/>
        </s:fill>
    </s:Rect>
    <s:Rect width="75" height="75">
        <s:fill>
            <s:SolidColor color="0x2f977d"/>
        </s:fill>
    </s:Rect>
    <s:Rect width="75" height="75">
        <s:fill>
            <s:SolidColor color="0xfffca2"/>
        </s:fill>
    </s:Rect>
    <s:Rect width="75" height="75">
        <s:fill>
            <s:SolidColor color="0xfffca2"/>
        </s:fill>
    </s:Rect>
    <s:Rect width="75" height="75">
        <s:fill>
            <s:SolidColor color="0xfffca2"/>
        </s:fill>
    </s:Rect>
</s:TileGroup>   

请指教!谢谢!

贾斯汀

有帮助吗?

解决方案

基于调整大小的重新划分会自动发生。但是,如果您不提供容器(您的 TileGroup 在这种情况下)使用一些特定的尺寸规则,它将应用其默认的大小行为,即适合其内容。显然,无论您处于肖像还是景观状态,内容都不会改变,因此什么也不会发生。

我不确定您要做什么,但是设置 width="100%" height="100%" 会拉伸 TileGroup 在整个屏幕上。即其大小将根据其父容器的大小而不是其内容来计算。因此,当状态更改时,列/行的数量将更改。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top