Delphi Android - detect device orientation change

杀马特。学长 韩版系。学妹 提交于 2019-11-30 15:41:46

In your form implement a method

procedure DoOrientationChanged(const Sender: TObject; const M: TMessage);

where you handle the current orientation. Subscribe for orientation changes in FormCreate like this

TMessageManager.DefaultManager.SubscribeToMessage(TOrientationChangedMessage, DoOrientationChanged);

and unsubscribe in FormDestroy like this:

TMessageManager.DefaultManager.Unsubscribe(TOrientationChangedMessage, DoOrientationChanged);

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;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!