0

一部のFlex3からFlex4コードをリファクタリングしており、SparkTabBarコントロールで問題が発生しました。4.5では、すべてのタブの幅より下にサイズを変更すると、タブが縮小します。Flex4でこれが表示されないので、グーグルを実行した後、解決策が見つからないようです。

発生しているように見えるのは、TabBarのminWidthが、すべてのボタンの合計にボタン間のギャップを加えたものに設定されていることです。

何かご意見は?最も役に立ちます。これは簡単だと思いましたが、修正できませんでした。

<s:TabBar id="myTabBar" top="0" width="100%" dataProvider="{myTabs}" >
    <s:layout>
        <s:HorizontalLayout gap="1" variableColumnWidth="true" />
    </s:layout>
</s:TabBar>

更新:
それが理想的なものかどうかはわかりませんが、私は解決策を考え出しました。デフォルトのTabBarSkinを使用して、メジャーメソッドを追加するように変更しました。測定方法では、タブを繰り返し処理し、ラベルオブジェクトを見つけて、幅を計算します。これを使用して、親コンポーネントのmaxWidthを設定します。動作しているように見えますが、このアプローチに関するコメントを歓迎します。上記のレイアウトタグも取り出しました。

        protected override function measure():void
        {
            //TODO Auto-generated method stub
            super.measure();


            // Calculate the maximum size of the button should stretch to and then set the host Component 
            // To the maxWidth.  This is accomplished by iterating through the children of the dataGroup 
            // and then getting the label components from labelDisplay.   Once you have that then we can 
            // get the PreferredBoundsWidth and add them all up.  The left and right values are added in as 
            // that is the spacing on each side of the label.  
            var totalButtonWidth:Number = 0;
            var tab:UIComponent;
            var calculatedWidth:Number;

            for (var i:int = 0; i < dataGroup.numElements; i++)
            {
                tab = dataGroup.getElementAt(i) as UIComponent;
                calculatedWidth = 0; 
                if (tab.hasOwnProperty("labelDisplay")) 
                {
                    var tabLabel:Label = (tab["labelDisplay"] as Label); 
                    calculatedWidth = tabLabel.getPreferredBoundsWidth() + tabLabel.left + tabLabel.right; 
                }
                totalButtonWidth = totalButtonWidth + calculatedWidth;

            }

            hostComponent.maxWidth = totalButtonWidth;
            trace("totalWidth is " + totalButtonWidth);
        }

思い出すと、SDKからスキンを取得して変更し、再利用しても大丈夫ですか?

4

1 に答える 1

1

はい、アップデートであなたが言ったことをすることは絶対にOKです。

ただし、既存のスキンを変更するよりも、独自のスキンを最初から定義する方がはるかに簡単な場合があります。このドキュメントをご覧ください。

于 2012-09-15T00:04:44.880 に答える