Delphi FMX中TRectangle虚线边框动画失效问题求助
FMX虚线边框动画无效果问题排查与解决
关键错误原因
- 属性名写错了:你要动画的
StrokeDashOffset其实是TRectangle.Stroke的DashOffset子属性,所以PropertyName得写成'Stroke.DashOffset',不是'StrokeDashOffset'——这是动画不生效的核心原因。 - 启动时机不对:在窗体
OnCreate事件里启动动画,此时控件还没完成渲染初始化,动画可能没法正常触发。把启动代码移到OnShow事件里更稳妥。
修正后的代码
边框设置(可保留在OnCreate)
Rectangle1.Stroke.Kind := TBrushKind.Solid; Rectangle1.Stroke.Dash := TStrokeDash.Dash; Rectangle1.Stroke.Color := TAlphaColors.Red; Rectangle1.Stroke.Thickness := 2; // 配置动画参数(这里只改PropertyName) FloatAnimation1.Parent := Rectangle1; FloatAnimation1.PropertyName := 'Stroke.DashOffset'; // 修正属性路径 FloatAnimation1.StartValue := 0; FloatAnimation1.StopValue := 20; FloatAnimation1.Duration := 1; FloatAnimation1.Loop := True; FloatAnimation1.AnimationType := TAnimationType.InOut; FloatAnimation1.Interpolation := TInterpolationType.Linear;
启动动画(移到FormShow事件)
procedure TForm1.FormShow(Sender: TObject); begin FloatAnimation1.Start; end;
额外检查项
- 确认
FloatAnimation1是设计时拖到窗体上的,或者代码里动态创建时正确分配了内存和Owner。 - 检查
FloatAnimation1.Enabled属性是否为True(默认是True,别被误改了)。
内容的提问来源于stack exchange,提问作者Eros
相关产品推荐
相关产品推荐

