0

我在列表中使用了自定义 IconItemRender。当我将图像嵌入列表并在设备上进行测试时,列表滚动的动画并不酷,它是滞后的。如果不嵌入图像列表滚动的动画是好的。

任何建议为什么列出滞后?

这是代码:

package components
{
import flash.display.Bitmap;
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.text.Font;
import flash.text.TextField;
import flash.text.TextFormat;

import mx.core.DPIClassification;

import spark.components.IconItemRenderer;
import spark.components.Image;
import spark.components.LabelItemRenderer;
import spark.components.supportClasses.StyleableTextField;

public class Shops extends IconItemRenderer
{   
    private static var bkgColor:Boolean;

    protected var storeName:StyleableTextField;
    protected var floor:StyleableTextField;
    protected var _data:Object;
    protected var floorTextSize:int;
    protected var promotions:Image;
    protected var promotionHolder:Sprite;

    [Embed(source="assets/map_list320.png")]
    public static const mapList:Class;

    public function Shops()
    {
        //TODO: implement function
        super();

        switch (applicationDPI) {

            case DPIClassification.DPI_160:

                floorTextSize = 11;
                break;

            case DPIClassification.DPI_240:

                floorTextSize = 20;
                break;

            case DPIClassification.DPI_320:

                floorTextSize = 16;
                break;
        }
    }

    /**
     * @private
     *
     * Override this setter to respond to data changes
     */
    override public function set data(value:Object):void
    {
        _data = value;

        if (storeName) storeName.text = _data.title;
        if (floor) floor.text = 'етаж: ' + _data.floor;

        // the data has changed.  push these changes down in to the 
        // subcomponents here           
    } 

    /**
     * @private
     * 
     * Override this method to create children for your item renderer 
     */ 
    override protected function createChildren():void
    {   
        // promotion if exist
        promotionHolder = new Sprite();
        addChild(promotionHolder);

        // store name
        storeName = new StyleableTextField();
        storeName.defaultTextFormat = new TextFormat( getStyle( "fontFamily" ), getStyle( "fontSize" ), getStyle('color') );
        addChild( storeName );

        // floor
        floor = new StyleableTextField();
        floor.defaultTextFormat = new TextFormat(getStyle( "fontFamily" ), floorTextSize, 0x999999);
        addChild(floor);

        // map


        var img:Image = new Image();
        img.source = mapList;
        img.cacheAsBitmap = true;
        img.width = 64;
        img.height = 64;
        addChild(img);
    }

    /**
     * @private
     * 
     * Override this method to change how the item renderer 
     * sizes itself. For performance reasons, do not call 
     * super.measure() unless you need to.
     */ 
    override protected function measure():void
    {

    }

    /**
     * @private
     * 
     * Override this method to change how the background is drawn for 
     * item renderer.  For performance reasons, do not call 
     * super.drawBackground() if you do not need to.
     */
    override protected function drawBackground(unscaledWidth:Number, unscaledHeight:Number):void
    {
        graphics.beginFill(bkgColor ? 0xFFFFFF : 0xf0f4fb, 1);
        graphics.drawRect(0, 0, unscaledWidth, unscaledHeight);

        bkgColor = !bkgColor;
    }

    /**
     * @private
     *  
     * Override this method to change how the background is drawn for this 
     * item renderer. For performance reasons, do not call 
     * super.layoutContents() if you do not need to.
     */
    override protected function layoutContents(unscaledWidth:Number, 
                                               unscaledHeight:Number):void
    {
        super.layoutContents(unscaledWidth, unscaledHeight);
        // layout all the subcomponents here            
    }

    override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
    {

        // position the field 
        storeName.x = unscaledWidth / 10;
        storeName.y = (unscaledHeight - (storeName.textHeight + floor.textHeight + (unscaledHeight/10))) / 2;

        floor.x = unscaledWidth / 10;
        floor.y = storeName.y + storeName.textHeight + (unscaledHeight/10);


        // we draw a separator line between each item
        var lineY:int = unscaledHeight -1;
        graphics.clear();
        graphics.lineStyle(1, 0xd9d9d9);
        graphics.moveTo( 0, lineY );
        graphics.lineTo( unscaledWidth, lineY );

        drawBackground(unscaledWidth, unscaledHeight);
    }
}

}

4

0 回答 0