0

我有一个收集信息的 AsyncTask。在收集信息时,我会出现一个进度条,上面写着“正在加载...”。问题是它出现在屏幕中央,宽度不做 fill_parent,我希望它到屏幕底部。这是我用来调用进度条的代码

进度条

    final ProgressDialog progDailog = new ProgressDialog(DashboardActivity.this);
    progDailog.setIndeterminate(false);
    progDailog.setCancelable(true);
    progDailog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    progDailog.show();
    progDailog.setContentView(R.layout.progress_circle);

我用于进度条的 xml 是这个

进度条的 XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:background="#00000000"
android:layout_gravity="bottom">

<LinearLayout android:layout_alignParentBottom="true"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:background="#7147d7"
    android:gravity="center"
    android:orientation="horizontal"
    android:paddingTop="5dip"
    android:paddingBottom="5dip"
    >
    <TextView android:id="@+id/loading"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:gravity="center"
        android:text="Loading..."
        android:textColor="#FFFFFF"
        />

</LinearLayout>



</RelativeLayout>
4

2 回答 2

0

以下代码适用于您想要
创建Dialogasyntask

Dialog mDialog = new Dialog(MainActivity.this);
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
Window window = mDialog.getWindow();
mDialog.setCanceledOnTouchOutside(false);
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
mDialog.setCancelable(false);
mDialog.setCanceledOnTouchOutside(false);
View dialogView = getLayoutInflater().inflate(R.layout.progressbar, null);
mDialog.setContentView(dialogView);


以下是进度条的布局文件:-

<?xml version="1.0" encoding="utf-8"?>

<ProgressBar
    android:id="@+id/progressBar1"
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_margin="10dp"
    android:indeterminate="true" />

于 2013-08-23T06:11:46.927 回答
0

尝试这个

height = getResources().getDisplayMetrics().heightPixels;

progDialog.getWindow().setGravity(Gravity.CENTER);
WindowManager.LayoutParams w = progressDialog.getWindow().getAttributes();
w.y = height / 4;
progDialog.getWindow().setAttributes(w);
progDialog.setCancelable(false);
于 2013-08-23T05:52:56.957 回答