如何在屏幕底部显示自定义进度条 - Android

时间:2013-08-23 05:45:32

标签: android xml android-progressbar

我有一个收集信息的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 FOR PROGRESS BAR

<?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>

2 个答案:

答案 0 :(得分: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);

答案 1 :(得分:0)

以下代码适用于您想要的 为Dialog

创建一个asyntask
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" />