delphi – 为FireMonkey中的ListBox添加字符串动画
发布时间:2020-12-15 04:03:38 所属栏目:大数据 来源:网络整理
导读:以下代码很好地动画将新字符串添加到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.O
以下代码很好地动画将新字符串添加到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中. 解决方法
要解决ListBox1.InsertObject和ListBox1.Items.Insert不起作用的事实,您可以执行以下操作
procedure TForm1.AddItem(s: string); var l : TListBoxItem; OldHeight : Single; I: Integer; index : integer; begin l := TListBoxItem.Create(nil); l.Text := s; OldHeight := l.Height; l.Height := 0; l.Opacity := 0; l.Index := 0; l.Parent := ListBox1; Index := Max(0,ListBox1.ItemIndex); for I := ListBox1.Count - 1 downto Index + 1 do begin ListBox1.Exchange(ListBox1.ItemByIndex(i),ListBox1.ItemByIndex(i-1)); end; ListBox1.ItemIndex := Index; l.AnimateFloat('height',0.5); end; 但有点荒谬.如果没有选择项目,它(最终)将字符串添加到位置0,否则在所选项目之前添加它.这个解决方案让我想起Bubble Sort.你需要将数学单元添加到uses子句中以使max函数起作用. 这确实似乎是FireMonkey中的一个错误(检查Quality Central #102122),但我怀疑未来的FireMonkey更新将解决这个问题.如果有人能看到更好的方式来做到这一点…. 对于那些感兴趣的人,我也是made a movie关于这一点,这更清楚地说明了事情. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |