【问题标题】:Progress dialog stuck on fragment transition进度对话框卡在片段转换上
【发布时间】:2014-12-15 05:10:21
【问题描述】:

我想在我的片段加载时显示进度对话框。 我正在转换片段中某些图像的大小,因此准备片段需要一些时间。但是在我显示进度对话框后,它并没有旋转,它只是卡住,直到片段准备好。

这是我的示例代码。 创建片段的代码:

//show progress bar
setProgressBarIndeterminateVisibility(true);
//Create fragment
MyFragment myFragment = new MyFragment();
setFragment(myFragment).commit();

在我的片段代码中:

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    setProgressBarIndeterminateVisibility(false);
}

【问题讨论】:

    标签: android android-fragments progressdialog


    【解决方案1】:

    每当应用“冻结”或卡住时,这是因为您正在主线程或 UI 线程上执行长时间运行的操作,例如减小图像大小。为了防止这种情况,请使用AsyncTask 在单独的线程上执行任何长时间运行的操作。 can be shown here 的一个例子。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多