here is my sample code in Firemonkey;
var
f: integer;
Label1: TLabel;
MyStringArray: TArray<String>;
Panel1: TPanel;
Layout1: TLayout;
begin
Layout1.Align := TAlignLayout.Client;
MyStringArray := ['aa','bb','cc','dd','ee','ff'];
f:= 10;
Layout1.BeginUpdate;
for i := 0 to length(MyStringArray) - 1 do
begin
Label1 := TLabel.Create(Self);
Label1.Name := 'Label' + i.ToString;
Label1.Text := 'Label_' + MyStringArray[i];
Label1.Position.Y := f;
Label1.Align := TAlignLayout.Top;
Label1.Parent := Layout1;
inc(f, 15);
end;
Layout1.EndUpdate;
end;
MyStringArray is a dynamic array no always with the same number of elements, so I resize a TPanel (Panel1) with the contents of TLayout (Layout1) according with number of labels;
Panel1.Height := Layout1.ChildrenRect.Height
This works fine when the number of labels grows in Layout1, but when the number of labels is less, Layout1.ChildrenRect.Height
has no effect and not shrinks it, height of the Layout1 always keeps the higher value.
Is there any solution or any other alternative to how to do it?, thanks Regards.