簡體   English   中英

Android用戶何時真正可以看到Delphi表單?

[英]When is a Delphi form actually visible to the user on Android?

我正在開發的游戲在首次加載時會進行一些預處理,因此我想向用戶顯示一個“加載%”,以表明該游戲未凍結。

我試圖通過等待主表單顯示給用戶,然后在執行預處理時顯示更新進度欄來做到這一點。

為了使預處理正常工作,我需要兩條信息:
1.表格以其最終尺寸顯示(在整個顯示屏上最大化)。
2.表單對用戶可見。

這是一條日志,顯示了在我的游戲加載時觸發表單事件的順序。 請記住,在以下任何事件中,我實際上都沒有使用代碼來更改表單的大小:

FormCreate
FormResize, clientSize : 0x0
FormResize, clientSize : 0x0
FormResize, clientSize : 0x0
FormResize, clientSize : 0x0
FormShow
FormActivate
FormResize, clientSize : 360x640

當前,我嘗試在最后一次調整大小時顯示加載屏幕(指示表單實際上是顯示的大小),但是此時,主表單仍然不可見(即使在FormShow和FormActivate之后),我最后顯示Android的默認“灰色漸變”屏幕,直到我的預處理代碼完成后才顯示進度條。

我嘗試在更新進度條后調用“ application.processmessages”,但這並沒有什么不同...

如何檢測我的主表單實際上對Android用戶可見?

[更新]
我創建了一個小應用程序來演示此問題:
https://github.com/bLightZP/Test_Splash

這個例子說明了使用的OnIdle,還應該如何執行。

unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Controls.Presentation, FMX.StdCtrls;

type
  TForm1 = class(TForm)
    ProgressBar1: TProgressBar;
  private
    FShown: Boolean;
    procedure ApplicationOnIdleHandler(Sender: TObject; var Done: Boolean);
    procedure ExecutePreProcessing;
    procedure ExecutePreProcessingSynchronized;
  public
    constructor Create(AOwner: TComponent); override;
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

constructor TForm1.Create(AOwner: TComponent);
begin
  inherited;
  // Method 1: Use OnIdle to execute code when the main form is visible:
  Application.OnIdle := ApplicationOnIdleHandler;
  // Method 2: Use a thread to execute the preprocessing. Comment out the line above if using this method, and uncomment the line below
  // TThread.CreateAnonymousThread(ExecutePreProcessingSynchronized).Start;
end;

procedure TForm1.ApplicationOnIdleHandler(Sender: TObject; var Done: Boolean);
begin
  if not FShown then
  begin
    FShown := True;
    ExecutePreProcessing;
  end;
end;

procedure TForm1.ExecutePreProcessing;
var
  I: Integer;
begin
  for I := 1 to 100 do
  begin
    Sleep(50);
    ProgressBar1.Value := I;
    Application.ProcessMessages; // <---- Not the best idea
  end;
end;

procedure TForm1.ExecutePreProcessingSynchronized;
var
  I: Integer;
begin
  for I := 1 to 100 do
  begin
    Sleep(50);
    // Ensure UI updates happen in the main thread
    TThread.Synchronize(nil,
      procedure
      begin
        ProgressBar1.Value := I;
      end
    );
  end;
end;

end.

BecameActive事件(ApplicationEvent)怎么樣? 使用本文並將其翻譯為Google翻譯http://delphifmandroid.blogspot.com/2016/09/delphi-android.html

啟動應用程序:

09-20 20:13:43.151: I/info(15893): FMX: Project1: FormCreate
09-20 20:13:43.151: I/info(15893): FMX: Project1: FormResize
09-20 20:13:43.151: I/info(15893): FMX: Project1: FormResize
09-20 20:13:43.161: I/info(15893): FMX: Project1: FormResize
09-20 20:13:43.161: I/info(15893): FMX: Project1: FormShow
09-20 20:13:43.161: I/info(15893): FMX: Project1: FormActivate
09-20 20:13:43.161: I/info(15893): FMX: Project1: Finished Launching
09-20 20:13:43.221: I/info(15893): FMX: Project1: FormPaint
09-20 20:13:43.231: I/info(15893): FMX: Project1: Became Active
09-20 20:13:43.261: I/info(15893): FMX: Project1: FormPaint
09-20 20:13:43.281: I/info(15893): FMX: Project1: FormPaint
09-20 20:13:43.311: I/info(15893): FMX: Project1: FormPaint

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM