我如何使用FireMonkey for Delphi XE5检测/处理屏幕旋转 [英] How do I detect / handle a screen rotate using FireMonkey for Delphi XE5

查看:83
本文介绍了我如何使用FireMonkey for Delphi XE5检测/处理屏幕旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先-我是Android和FireMonkey编程的初学者,因此请记住这一点:-).

First of all - I am a beginner when it comes to Android and FireMonkey programming, so please bear this in mind :-).

我制作了一个FireMonkey/Android应用程序,可以根据屏幕尺寸和方向调整控件的大小/重新排列控件的大小,但是当用户旋转屏幕时,我不知道如何设置应用程序的调用方式.如果我在其中运行Firemonkey/Win32并显示一个执行以下操作的按钮:

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;

,然后捕获FormResize事件,我的窗体将按照其大小调整大小/重排.我想在Android上运行时执行相同的操作,但是似乎在屏幕旋转时不会调用FormResize事件,因此我的按钮等没有被重排并最终出现在屏幕外.

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?

推荐答案

如果无法使表单的 OnResize 事件起作用,则可以订阅FMX方向已更改的消息,从而:/p>

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;

这篇关于我如何使用FireMonkey for Delphi XE5检测/处理屏幕旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆