In an Android app, I'm trying to create a Label at runtime into a rectangle, and all of the properties works fine except for the Horizontal Align of the text. Is something wrong with my code?
procedure TForm7.Button1Click(Sender: TObject);
var
lb : TLabel;
begin
lb := TLabel.Create(Rectangle1);
lb.Parent := Rectangle1;
lb.Align := TAlignLayout.Center;
lb.TextSettings.HorzAlign := TTextAlign.Leading;
lb.Width := 300;
lb.TextSettings.Font.Size := 12;
lb.StyledSettings:=[TStyledSetting.Family,TStyledSetting.Style,
TStyledSetting.FontColor,TStyledSetting.Size,TStyledSetting.Other];
lb.Margins.Bottom := 100;
lb.Text := 'Programming Language is Delphi 10.4 31/3/2022';
end;
CodePudding user response:
You need to read up on FMX.Graphics.ITextSettings. You will find that there is an important relation between TStyledSettings
and TTextSettings
.
In your question you are concerned with horizontal alignment not following your setting:
lb.TextSettings.HorzAlign := TTextAlign.Leading;
That is because you have overruled it by including TStyledSetting.Other
in lb.StyledSettings
.
Remove that TStyledSetting.Other
from lb.StyledSettings
and you will see that HorzAlign
, VertAlign
, Trimming
and WordWrap
will follow your own settings.