First of all - I am a beginner when it comes to Android and FireMonkey programming, so please bear this in mind :-).
I have made a FireMonkey/Android application that can resize/reflow its controls according to the screen size and orientation, but I can't figure out how I set my application up to be called, when the user rotates the screen. If I run in it Firemonkey/Win32 and show a button that does the following:
PROCEDURE TMainForm.FlipForm;
VAR
W,H : INTEGER;
BEGIN
W:=Width; H:=Height; Width:=H; Height:=W
END;
and then trap the FormResize event, my form resizes/reflows as it should. I would like to do the same when running on Android, but it seems like the FormResize event doesn't get called when the screen rotates, so my buttons etc. is not reflowed and ends up outside the screen.
So my question is, how do I detect that the screen has rotated so that I can have my application work in both Landscape and Portrait mode?
If you can't get the form's OnResize
event to work, then you can subscribe to the FMX orientation changed message thus:
uses
FMX.Forms, FMX.Messages, FMX.Types;
//In the definition of TFooForm you define:
FOrientationChangedId: Integer;
procedure OrientationChangedHandler(const Sender: TObject; const Msg: TMessage);
//Subscribe to orientation change events in OnCreate or similar
FOrientationChangedId := TMessageManager.DefaultManager.SubscribeToMessage(
TOrientationChangedMessage, OrientationChangedHandler);
//Unsubscribe from orientation change events in OnDestroy or similar
TMessageManager.DefaultManager.Unsubscribe(
TOrientationChangedMessage, FOrientationChangedId);
procedure TFooForm.OrientationChangedHandler(const Sender: TObject; const Msg: TMessage);
begin
Log.d('Orientation has changed');
end;