【问题标题】:Row renderer with height depending on row index高度取决于行索引的行渲染器
【发布时间】:2014-03-14 14:41:06
【问题描述】:

我有一个IDropInListItemRenderer,它在List 中使用。行的高度取决于数据及其在List 视图中的位置。

如何在行索引更改后立即重新测量?

updateDisplayList 不会每次都被调用,而且到那时为时已晚,因为List 已经测量过了。

编辑

我想要达到的效果类似于 iOS,其中一个部分的标题贴在顶部

以下是无法正确测量的基本渲染器:

import mx.controls.Label;
import mx.controls.listClasses.BaseListData;
import mx.controls.listClasses.IDropInListItemRenderer;
import mx.controls.listClasses.IListItemRenderer;
import mx.core.UIComponent;
import mx.events.FlexEvent;

public class MyRowRenderer extends UIComponent implements IListItemRenderer, IDropInListItemRenderer {
    private static const HEADER_HEIGHT:int = 20;
    private static const LABEL_HEIGHT:int = 20;

    private var _data:Object;
    private var _label:Label;
    private var _header:Label;
    private var _listData:BaseListData;

    public function MyRowRenderer() {
        super();
    }

    [Bindable("dataChange")]
    public function get data():Object {
        return _data;
    }

    public function set data(value:Object):void {
        this._data = value;
        invalidateProperties();
        dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
    }

    [Bindable("dataChange")]
    public function get listData():BaseListData {
        return _listData;
    }

    public function set listData(value:BaseListData):void {
        _listData = value;
    }

    override protected function createChildren():void {
        super.createChildren();

        _header = new Label();
        addChild(_header);

        _label = new Label();
        addChild(_label);
    }

    override protected function measure():void {
        super.measure();

        if (_label == null || _header == null) {
            return;
        }

        var h:Number = LABEL_HEIGHT;

        if (_listData.rowIndex == 0) {
            h += HEADER_HEIGHT;
        }

        explicitHeight = measuredHeight = height = h;
    }

    override protected function commitProperties():void {
        super.commitProperties();

        _label.text = _data.label;
        _header.text = _data.header;
    }

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

        _header.visible = _header.includeInLayout = (_listData.rowIndex == 0);

        if (_header.visible) {
            _header.move(0, 0);
            _header.setActualSize(unscaledWidth, HEADER_HEIGHT);

            _label.move(0, HEADER_HEIGHT);
            _label.setActualSize(unscaledWidth, LABEL_HEIGHT);
        } else {
            _label.move(0, 0);
            _label.setActualSize(unscaledWidth, LABEL_HEIGHT);
        }
    }
}

}

【问题讨论】:

  • 你能提供工作代码吗?为什么不尝试使用 inline itemRenderer 有任何具体原因?

标签: apache-flex flex3


【解决方案1】:

我最终创建了List 的子类并覆盖shiftRow 函数以调度自定义RowIndexChangeEvent。在行渲染器的set listData 中,它为RowIndexChangeEvent 的所有者添加了一个事件侦听器,并使其属性、大小和显示列表无效。

【讨论】:

    猜你喜欢
    • 2013-10-03
    • 1970-01-01
    • 1970-01-01
    • 2015-08-15
    • 1970-01-01
    • 2021-07-06
    • 2010-10-06
    相关资源
    最近更新 更多