Android ProgressDialog显示不正确

Android ProgressDialog显示不正确,android,progressdialog,Android,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 =

我尝试在我的应用程序中实现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);
});
当此代码在一个应用程序会话中第一次执行时,“我的进度”对话框会错过他的填充,如下所示:

下一次代码执行对话框时,一切正常:


如何始终正确显示进度对话框?

更改为
pd.setUndeterminate(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_水平);
浮动持续时间=(浮动)(mModel.getGifEndPosition()-mModel.getGifStartPosition());
inttotalframes=(int)((持续时间/秒,单位为毫秒)*mModel.getFps());
pd.setMax(总帧数);
pd.setUndeterminate(假);//getInstance(ctx).killRunningProcesses());
pd.show();
mBuilder.setProgressListener((f,ft)->{
pd.setMessage(ctx.getString(R.string.frames_processed));
pd.SetUndeterminate(假);
新线程(()->{
pd.进度(f);
pd.设置秒程序(f);
}).start();
});
mBuilder.setCompleteListener(路径设置如果->{
pd.解散();
goToPreview(pathToGif);
});

很抱歉,但这对我没有帮助:(将此选项设置为false jsut将禁用进度条动画,直到部分工作开始。请共享所有java文件。无需共享此文件,所有与进度侦听器绑定的代码都会附加到alreadyprogressDialog,在开始执行任何进度之前不会填充
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);
});