-1

在我的项目中,我有一个面板,它使用我基于 Spark 面板皮肤创建的自定义皮肤。在这个皮肤中,我向显示组(“contentGroup”)添加了一个 Spark Scroller,我向该组添加了具有一些标签和图像的“ListItems”。

直到今天,当我注意到当垂直滚动条到达底部时,一切都运行良好,仍然有内容要显示,如图所示:

(由于我不能发布图片,这里是链接:http ://s10.postimage.org/uwfqfqp15/Panel.jpg )

正如您在图像中看到的那样,Scroller 垂直滚动条已经到了尽头,但仍有一些东西低于下限(您可以看到我的简单自定义滚动条还没有到达底部)。

这是面板皮肤代码的一部分(滚动条部分):

面板皮肤.mxml:

<s:Group id="algoGroup" x="0" y="0" width="100%" height="100%" minWidth="0" minHeight="0">
    <s:Scroller id="contentScroller" x="0" y="0" width="85%" height="100%" minWidth="0" minHeight="0">
        <s:Group id="contentGroup" x="0" y="0" width="85%" height="100%" minWidth="0" minHeight="0">
        </s:Group>
    </s:Scroller>
    <componentes:customScroller id="contentScrollbar" x="10" y="10" width="10%" height="100%"/>
</s:Group>

ListaItem.mxml

<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
     xmlns:s="library://ns.adobe.com/flex/spark" 
     xmlns:mx="library://ns.adobe.com/flex/mx"
     contentBackgroundAlpha="0.0"
     currentState="Horizontal"
     width.Horizontal="200" height.Horizontal="100"
     height.Vertical="260" width.Vertical="128">
<s:states>
    <s:State name="Horizontal"/>
    <s:State name="Vertical"/>
</s:states>
<fx:Declarations>
<fx:Script>
    <![CDATA[

        import objectos.GlobalVars;

        /*Vars - State -> Vertical
        Bindable Vars -- Omitted
        */

        public var ID:Number = -1;

        public function resize(nW:Number, nH:Number):void
        {
            if(this.currentState == "Vertical")
            {
                _realIW = _iW2 = (_iW2 * nW) / _w2;
                _realIH = _iH2 = (_iH2 * nH) / _h2;

                if(_iW2 > _iH2)
                    _iW2 = _iH2;
                else
                    _iH2 = _iW2;

                _xImg = (_xImg * nW) / _w2;
                _yImg = (_yImg * nH) / _h2;

                _xTit = (_xTit * nW) / _w2;
                _yTit = (_yTit * nH) / _h2;
                Titulo.width = (Titulo.width * nW) / _w2;

                Titulo.setStyle("fontSize", (GlobalVars.instance.getGlobal("fontSize") * 0.9));

                _xDes = (_xDes * nW) / _w2;

                if(Titulo.measureText(Titulo.text).width > Titulo.width)
                    _yDes = (_yDes * nH) / _h2;
                else
                    _yDes = Titulo.y + Titulo.measureText(Titulo.text).height;

                Descricao.width = (Descricao.width * nW) / _w2;

                Descricao.setStyle("fontSize", (GlobalVars.instance.getGlobal("fontSize") * 0.7));

                _xPre = (_xPre * nW) / _w2;
                _yPre = (_yPre * nH) / _h2;
                Preco.width = (Preco.width * nW) / _w2;

                _xIco = (_xIco * nW) / _w2;
                _yIco = (_yIco * nH) / _h2;
                IconEspecial.width = (IconEspecial.width * nW) / _w2;
                IconEspecial.height = (IconEspecial.height * nH) / _h2;

                _xDeL = (_xDeL * nW) / _w2;
                _yDeL = (_yDeL * nH) / _h2;
                DescricaoL.width = (DescricaoL.width * nW) / _w2;

                DescricaoL.setStyle("fontSize", (GlobalVars.instance.getGlobal("fontSize") * 0.7));
            }
            else
            {
                _realIW = _iW = (_iW * nW) / _w;
                _realIH = _iH = (_iH * nH) / _h;

                if(_iW > _iH)
                    _iW = _iH;
                else
                    _iH = _iW;

                Imagem.x = (Imagem.x * nW) / _w;
                Imagem.y = (Imagem.y * nH) / _h;

                Titulo.x = (Titulo.x * nW) / _w;
                Titulo.y = (Titulo.y * nH) / _h;
                Titulo.width = (Titulo.width * nW) / _w;

                Titulo.setStyle("fontSize", (GlobalVars.instance.getGlobal("fontSize") * 0.9));

                Descricao.x = (Descricao.x * nW) / _w;
                Descricao.y = (Descricao.y * nH) / _h;
                Descricao.width = (Descricao.width * nW) / _w;

                Descricao.setStyle("fontSize", (GlobalVars.instance.getGlobal("fontSize") * 0.7));

                Preco.x = (Preco.x * nW) / _w;
                Preco.y = (Preco.y * nH) / _h;
                Preco.width = (Preco.width * nW) / _w;

                IconEspecial.x = (IconEspecial.x * nW) / _w;
                IconEspecial.y = (IconEspecial.y * nH) / _h;
                IconEspecial.width = (IconEspecial.width * nW) / _w;
                IconEspecial.height = (IconEspecial.height * nH) / _h;

                _sW = (_sW * nW) / _w;
                _sY = (_sY * nH) / _h;
            }
        }

        private function resizeImg():void
        {
            var ratio:Number = Imagem.contentWidth / Imagem.contentHeight;

            if(Imagem.contentWidth > Imagem.contentHeight)
            {
                if(this.currentState == "Vertical")
                {
                    Imagem.width = _iW2;
                    Imagem.height = _iW2 / ratio;   
                }
                else
                {
                    Imagem.width = _iW;
                    Imagem.height = _iW / ratio;
                }
            }
            else
            {
                if(Imagem.contentHeight > Imagem.contentWidth)
                {
                    if(this.currentState == "Vertical")
                    {
                        Imagem.height = _iH2;
                        Imagem.width = _iH2 * ratio;
                    }
                    else
                    {
                        Imagem.height = _iH;
                        Imagem.width = _iH * ratio;
                    }
                }
                else
                {
                    if(this.currentState == "Vertical")
                    {
                        Imagem.height = (_iH2 > _iW2)?_iW2:_iH2;
                        Imagem.width = ((_iH2 > _iW2)?_iW2:_iH2) * ratio;
                    }
                    else
                    {
                        Imagem.height = (_iH > _iW)?_iW:_iH;
                        Imagem.width = ((_iH > _iW)?_iW:_iH) * ratio;
                    }
                }
            }

            Imagem.x += (_realIW - Imagem.width) / 2;
            Imagem.y += (_realIH - Imagem.height) / 2;
        }

        public function get useBar():Boolean
        {
            if(Separador != null)
                return Separador.visible;
            else
                return false;
        }
        public function set useBar(value:Boolean):void
        {
            if(Separador != null)
                Separador.visible = value;
        }
    ]]>
</fx:Script>
<mx:Image id="Imagem" x.Horizontal="10" y.Horizontal="10" x.Vertical="{_xImg}" y.Vertical="{_yImg}" maintainAspectRatio="false" complete.Horizontal="resizeImg()" complete.Vertical="resizeImg()"/>
<s:Label id="Titulo" x="98" y="10" text="Label" width="102" maxDisplayedLines="2" x.Vertical="{_xTit}" y.Vertical="{_yTit}" verticalAlign.Vertical="middle" textAlign.Vertical="left"/>
<s:Label id="Descricao" x="98" y="43" text="Label" width="102" maxDisplayedLines="3" color="#999999" x.Vertical="{_xDes}" y.Vertical="{_yDes}"/>
<s:Label id="Preco" x="113" y="78" text="Label" width="87" maxDisplayedLines="1" x.Vertical="{_xPre}" y.Vertical="{_yPre}"/>
<mx:Image x="93" y="73" width="20" height="20" id="IconEspecial" x.Vertical="{_xIco}" y.Vertical="{_yIco}"/>
<mx:HRule id="Separador" x="0" y="{_sY}" width="{_sW}" strokeColor="#000000" shadowColor="#000000" includeIn="Horizontal"/>
<s:Label id="DescricaoL" x.Horizontal="1" y.Horizontal="177" x.Vertical="{_xDeL}" y.Vertical="{_yDeL}" text="Label" width="127" color="#999999" visible.Horizontal="false" maxDisplayedLines="3"/>
</s:Group>

这是用于动态添加组件的代码(编辑为仅包含相关部分):

        var item:ListaItem = new ListaItem();

        var iW:Number = 0;
        var iH:Number = 0;

        if(yPos == -1 || xPos == -1)
        {
            yPos = 0 - ((_group.height - (10 * (_maxProdutosVisiveis - 1))) / _maxProdutosVisiveis) - 10;
            xPos = 0;
        }

        yPos += ((_group.height - (10 * (_maxProdutosVisiveis - 1))) / _maxProdutosVisiveis) + 10;
        xPos = 0;
        iW = _group.width;
        iH = ((_group.height - (10 * (_maxProdutosVisiveis - 1))) / _maxProdutosVisiveis);

        item.x = xPos;
        item.y = yPos;

        item.ID = obj.idProduto;
        item.Titulo.text = (obj.Titulo_Produto != null)?obj.Titulo_Produto:obj.Titulo;
        item.Descricao.text = obj.Descricao;
        item.Preco.text = obj.Valor + " €";

        item.IconEspecial.source = this.specialIcon;

        _margem = iH + 10; 

        item.addEventListener(MouseEvent.CLICK, goToApresentacao);

        _group.addElement(item);
        _components.addItem(item);

        item.width = iW;
        item.height = iH;

        item.Imagem.source = obj.url;

_maxProdutosVisiveis是同时最大可见产品 obj是保存 ListItem 数据的对象

我认为我已经包含了所有相关的内容,但请随时要求其他任何内容。

有没有办法解决这个问题?

谢谢你的帮助 :)

4

1 回答 1

3

经过数小时的搜索并尝试解决问题的不同方法后,我注意到我忘记为 ListaItem 添加默认高度和宽度。

改变:

ListaItem.mxml

<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx"
    contentBackgroundAlpha="0.0"
    currentState="Horizontal"
    width.Horizontal="200" height.Horizontal="100"
    height.Vertical="260" width.Vertical="128">

至:

<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx"
    contentBackgroundAlpha="0.0"
    currentState="Horizontal"
    width="200" height="100"
    height.Vertical="260" width.Vertical="128">

让一切重新工作。无论如何谢谢大家:)

于 2012-04-18T21:49:45.270 回答