我尝试在我的应用程序中实现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);
});
当这个代码在一个应用程序会话期间第一次执行时,我的进度对话框会错过他的填充,如下所示:
以及我的代码执行对话的所有下一次都没关系:
如何才能正确显示我的进度对话框?
答案 0 :(得分: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);
});