0

I have a AsyncTask that gathers information. While its gathering information I have a progress bar appear saying "Loading...". The problem is it appears in the center of the screen, the width doesn't do fill_parent and I want it to go to the bottom of the screen. Here is the code I use to call the progress bar

Progress Bar

    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);

The xml I use for the progress bar is this

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 Answers2

0

Try this

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);
sanky jain
  • 873
  • 1
  • 6
  • 14
  • remove everything just try this progDialog.getWindow().setGravity(Gravity.BOTTOM); Also remove linear layout why you need two layouts – sanky jain Aug 23 '13 at 05:59
0

Following code is works for as you want
create a Dialog as for your 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);


Following is layout file for progressbar:-

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

Pravin
  • 1,362
  • 12
  • 21