【问题标题】:White bar appears behind progress indicator进度指示器后面出现白条
【发布时间】:2015-03-01 22:53:43
【问题描述】:

我的加载圈工作正常,但后面有一个白框,如 here 所示。我花了几个小时寻找解决方案,我发现的所有 SO 帖子都提出了一种与我使用的非常相似的实现。我还尝试将自定义主题应用于对话框并设置透明度,但这没有任何作用。我不确定白色矩形实际上是什么,因为更改 ProgressBar 本身的属性似乎只会影响包含图像的中心正方形。

我为在 AsyncTask 期间运行的进度条定义了以下布局。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:background="@android:color/transparent" >

    <ProgressBar
        android:id="@+id/progressBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:indeterminate="true"/>

</FrameLayout>

下面是我使用上面显示的布局的对话框的方法。

    public static ProgressDialog createProgressDialog(Context mContext) {
        ProgressDialog dialog = new ProgressDialog(mContext);
        try {
            dialog.show();
        } catch (WindowManager.BadTokenException e) {

        }
        dialog.setCancelable(false);
        dialog.setContentView(R.layout.progressdialog);
        return dialog;
    }

    public class FetchAcroTask extends AsyncTask<String, Void, String[]> {

        Dialog progressDialog = null;

        @Override
        protected void onPreExecute() {

            // Display loading circle
            if (progressDialog == null) {
                progressDialog = createProgressDialog(AcroActivity.this);
                progressDialog.show();
            } else {
                progressDialog.show();
            }
        }

        @Override
        protected String[] doInBackground(String... params) {

            if (params.length == 0) {
                return null;
            }
            return GET(params[0]);
        }

        @Override
        protected void onPostExecute(String[] resultStrs) {

            if (resultStrs == null) {
                acroAdapter.add("No results were found");
            } else {
                acroAdapter.addAll(resultStrs);
            }

            // Dismiss loading circle
            progressDialog.dismiss();

        }
    }
}

提前致谢。

【问题讨论】:

  • 您正在创建一个实际进度对话框。您必须使用进度条。通过它的 id 找到它的视图,然后显示它或关闭它....
  • 你需要让你的对话框透明stackoverflow.com/questions/10795078/…

标签: android android-progressbar indicator


【解决方案1】:

感谢 Kostas 留下的评论,我找到了解决方案。

我将我的 ProgressBar 声明转移到我的活动布局文件中,并在我的 AsyncTask 完成时简单地隐藏它。

在我的活动布局文件中:

<ProgressBar
    android:id="@+id/progressBar1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true" />

在异步任务中:

    @Override
    protected void onPostExecute(String[] resultStrs) {

        if (resultStrs == null) {
            acroAdapter.add("No results were found");
        } else {
            acroAdapter.addAll(resultStrs);
        }

        // Dismiss loading circle
        progressBar = (ProgressBar) findViewById(R.id.progressBar1);
        progressBar.setVisibility(View.INVISIBLE);
    }

谢谢。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-06
    • 1970-01-01
    • 1970-01-01
    • 2021-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-29
    相关资源
    最近更新 更多