以下代码可以很好地为ListBox添加新字符串时进行动画处理。
procedure TForm6.AddItem(s: string);
var
l : TListBoxItem;
OldHeight : Single;
begin
l := TListBoxItem.Create(Self);
l.Text := s;
OldHeight := l.Height;
l.Height := 0;
l.Parent := ListBox1;
l.Opacity := 0;
l.AnimateFloat('height', OldHeight, 0.5);
l.AnimateFloat('Opacity', 1, 0.5);
end;
这个项目会展开并淡出。但是我希望能够将字符串添加到ListBox中的任意位置 - 实际上是在当前的ItemIndex处。有人知道如何做吗?