2016-11-26 167 views
2

我嘗試實施progressDialog在我的應用程序,在這裏我的代碼:ProgressDialog顯示不正確的

final ProgressDialog pd = new ProgressDialog(ctx); 
pd.setTitle(R.string.creating_a_gif); 
pd.setMessage(ctx.getString(R.string.preprocessing)); 
pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); 
float duration = (float) (mModel.getGifEndPosition() - mModel.getGifStartPosition()); 
int totalFrames = (int) ((duration/SECOND_IN_MILLIS) * mModel.getFps()); 
pd.setMax(totalFrames); 
pd.setIndeterminate(true); 
pd.setCancelable(false); 
pd.setCanceledOnTouchOutside(false); 
pd.setButton(DialogInterface.BUTTON_NEGATIVE, 
    ctx.getString(android.R.string.cancel), 
    (dialogInterface, i) -> FFmpeg.getInstance(ctx).killRunningProcesses()); 
pd.show(); 

mBuilder.setProgressListener((f, ft) -> { 
    pd.setMessage(ctx.getString(R.string.frames_processed)); 
    pd.setIndeterminate(false); 
    new Thread(() -> { 
    pd.setProgress(f); 
    pd.setSecondaryProgress(f); 
    }).start(); 
}); 
mBuilder.setCompleteListener(pathToGif -> { 
    pd.dismiss(); 
    goToPreview(pathToGif); 
}); 

當這個代碼是一個應用程序會話中執行第一次,我的進度對話框想念他的補白是這樣的: enter image description here

和所有未來的時間我的代碼進行對話是好的:

enter image description here

我能做些什麼來正確顯示我的進度對話框?

回答

0

更改爲pd.setIndeterminate(false);

final ProgressDialog pd = new ProgressDialog(ctx); 
pd.setTitle(R.string.creating_a_gif); 
pd.setMessage(ctx.getString(R.string.preprocessing)); 
pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); 
float duration = (float) (mModel.getGifEndPosition() - mModel.getGifStartPosition()); 
int totalFrames = (int) ((duration/SECOND_IN_MILLIS) * mModel.getFps()); 
pd.setMax(totalFrames); 
pd.setIndeterminate(false); //<--- change to false 
pd.setCancelable(false); 
pd.setCanceledOnTouchOutside(false); 
pd.setButton(DialogInterface.BUTTON_NEGATIVE, 
    ctx.getString(android.R.string.cancel), 
    (dialogInterface, i) -> FFmpeg.getInstance(ctx).killRunningProcesses()); 
pd.show(); 

mBuilder.setProgressListener((f, ft) -> { 
    pd.setMessage(ctx.getString(R.string.frames_processed)); 
    pd.setIndeterminate(false); 
    new Thread(() -> { 
    pd.setProgress(f); 
    pd.setSecondaryProgress(f); 
    }).start(); 
}); 
mBuilder.setCompleteListener(pathToGif -> { 
    pd.dismiss(); 
    goToPreview(pathToGif); 
}); 
+0

抱歉,但它確實沒有幫助我:(打開這個選項爲false,僅僅指剛禁用進度條aniimation直到工作的某一部分開始 –

+0

沒有,仍然沒有工作 –

+0

請分享所有的Java文件 –