德尔福的Android - 检测设备方向变化
新双方德尔福Android开发。我如何检测屏幕的方向发生了变化?即,从纵向到横向,反之亦然?而且我怎么火过code当出现这种情况?比如我有一个图像大小在比方说在纵向模式下安全工程师,但当器件切换为横向,我希望它来调整,并采取了整个屏幕宽度。
New to both Delphi Android development. How do I detect that the screen orientation has changed? i.e. from Portrait to Landscape and vice versa? And how do I fire off code when this happens? For example I have an image sized at let's say 300x200 in portrait mode but when the device switches to landscape I want it to adjust and take up full screen width.
在您的形式实现的方法
procedure DoOrientationChanged(const Sender: TObject; const M: TMessage);
在这里你处理当前的方向。认购FORMCREATE这样的方向变化。
where you handle the current orientation. Subscribe for orientation changes in FormCreate like this
TMessageManager.DefaultManager.SubscribeToMessage(TOrientationChangedMessage, DoOrientationChanged);
和在FormDestroy退订这样的:
and unsubscribe in FormDestroy like this:
TMessageManager.DefaultManager.Unsubscribe(TOrientationChangedMessage, DoOrientationChanged);
要找出当前的屏幕方向只问IFMXScreenService:
To find out the current screen orientation just ask IFMXScreenService:
var
screenService: IFMXScreenService;
begin
if TPlatformServices.Current.SupportsPlatformService(IFMXScreenService, screenService) then begin
case screenService.GetScreenOrientation of
TScreenOrientation.Portrait: ;
TScreenOrientation.Landscape: ;
TScreenOrientation.InvertedPortrait: ;
TScreenOrientation.InvertedLandscape: ;
end;
end;
end;