Flex 4: Setting Spark List height to its content height

How to set a Spark List height to the height of its content?

Tried this:

var lastRow:IVisualElement =
myList.dataGroup.getElementAt(myList.dataGroup.numElements - 1);
myList.height = lastRow.y + lastRow.height;

It works in case of a single item, but lastRow is null in case of more items.

flex flex4

share|improve this question

asked Apr 1 '10 at 9:34

关于flex4 list 高度适应内容-LMLPHP

alexey

2,83832553

5 Answers

active oldest votes

20 accepted

In mxml you can do it like so:

<s:List width="100%">
<s:layout>
<s:VerticalLayout useVirtualLayout="false" requestedMinRowCount="1"/>
</s:layout>
</s:List>

You set the requestedMinRowCount or the requestedRowCount in the layout inside the List. It got me before, too. Hope that helps.

share|improve this answer

answered Sep 29 '10 at 22:17

关于flex4 list 高度适应内容-LMLPHP

Marty

21633

I'm trying to get this to work with TileLayout, but there is no requestedMinRowCount for TileLayout. I wonder how to get the height to dynamically set for the list when using TileLayout so that the list only takes up space for which it needs to display it's rows? –  Stephen Horvath Aug 30 '11 at 18:03

2

For TileList I did it like this:

<s:List width="100%" height="{(tilelayout.rowCount * tilelayout.rowHeight) + ((tilelayout.rowCount - 1) * tilelayout.verticalGap)}">
<s:layout>
<s:TileLayout id="tilelayout" rowHeight="190" columnWidth="130" horizontalGap="5" verticalGap="10" />
</s:layout>
</s:List>

share|improve this answer

edited Aug 31 '11 at 0:40

answered Aug 30 '11 at 18:14

关于flex4 list 高度适应内容-LMLPHP

Stephen Horvath

1138

2

try this layout - for regular list

<s:layout>
<s:VerticalLayout horizontalAlign="contentJustify"
gap="0"
verticalAlign="middle"
variableRowHeight="false"/>
</s:layout>

share|improve this answer

answered Nov 22 '11 at 11:35

关于flex4 list 高度适应内容-LMLPHP

Amalia

211

0

public class MyTileLayout extends TileLayout
{ override public function updateDisplayList(w:Number, h:Number):void
{
super.updateDisplayList(w,h); target.height = rowCount*rowHeight + verticalGap*(rowCount - 1);
} }

Or you can extend your TileLayout :)

share|improve this answer

answered Nov 4 '11 at 15:08

关于flex4 list 高度适应内容-LMLPHP

Katya

1

0

Easiest way to do this

height="{list.dataGroup.contentHeight}"

share|improve this answer

04-13 18:00