2016-11-26 158 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文件 –