简体   繁体   English

从itemrenderer访问布局数据

[英]Accessing layout data from itemrenderer

I am working on a FLEX / AIR Spark list which lists a collection of images with differing width and height. 我正在处理FLEX / AIR Spark列表,该列表列出了宽度和高度不同的图像集合。

I am using a custom layout which works this way: 我正在使用一种自定义布局,其工作方式如下:

  • decide how many images can be fit in the current row based on their widths. 根据图像的宽度确定在当前行中可以容纳多少图像。

  • justify them in such a way that first image in the row obeys the "left" margin and the last image in the row obeys "right" margin, so with the "top" and "bottom" as specified by the user, let us say 10 pixels. 用以下方式证明它们的合理性:该行中的第一个图像遵循“左”边距,而该行中的最后一个图像遵循“右”边距,因此用户指定的“顶部”和“底部” 10像素

  • As an example, assuming that the current row has 4 images, the images 1 & 4 will have 10 pixels each as "left" margin "right" margin respectively. 作为示例,假设当前行具有4张图像,则图像1和4将分别具有10个像素,分别作为“左”边距“右”边距。 But the left and right gaps between 1-2, 2-3 & 3-4 will be equally divided based on the varying widths. 但是1-2、2-3和3-4之间的左右间隙将根据宽度的变化而平均分配。

  • now i would like to draw a background that will fill the dynamic area. 现在,我想绘制一个可以填充动态区域的背景。 Please see the image below to get an idea: 请查看下图以了解想法:

Layout requirement Image 布局要求图

** In the image, The grey area is the background I would like to draw, and the colored rectangles represent images of differing widths and heights.** **在图像中,灰色区域是我要绘制的背景,彩色矩形代表宽度和高度不同的图像。**

  • the "rowHeight" is variable based on the maximum height of individual images within the row. “ rowHeight”是基于行中单个图像的最大高度而变化的。

Issues: 问题:

a) Now I would like to draw a background (see the grey area in the pic) that fills the background area of the list. a)现在,我想绘制一个填充列表背景区域的背景(请参见图片中的灰色区域)。 I know the current item's width & height, but I don't know the rowHeight decided by the layout, left and right margins between the images. 我知道当前项目的宽度和高度,但我不知道rowHeight由布局,图像之间的左右边距决定。

Something like: 就像是:

bgRect:Rectangle = new rectangle ( 0, 0, (imgWidth + (LeftMargin/2) + (Right Margin/2) ), rowHeight)

b) How / where should the background be implemented? b)如何/在哪里实施背景? if i add the BG area within the item renderer based on the layout, again the layout will be relaid. 如果我根据布局在项目渲染器中添加BG区域,则会再次布局。

Children should be added in the createChildren method. 应该在createChildren方法中添加子级。 Drawing (painting) the background should happen in updateDisplayList method. 绘制(绘画)背景应该在updateDisplayList方法中进行。

You can pass data to your itemrenderers via an itemrenderer factory. 您可以通过itemrenderer工厂将数据传递到itemrenderer。 See - Flex - Sending a parameter to a custom ItemRenderer? 参见-Flex-向自定义ItemRenderer发送参数? .

var productRenderer:ClassFactory = new ClassFactory(ProductRenderer); var productRenderer:ClassFactory = new ClassFactory(ProductRenderer); productRenderer.properties = { showProductImage: true }; productRenderer.properties = {showProductImage:true}; myList.itemRenderer = productRenderer; myList.itemRenderer = productRenderer;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM