0

我有一个进度条,我在代码中创建了我的活动。这是代码:

progressDialog = new ProgressDialog(this); 
// Progress bar message.
String progressBarMessage = "Loading, please wait...";
progressDialog.getWindow().setGravity(Gravity.BOTTOM);

progressDialog.setCancelable(false);
progressDialog.setMessage(progressBarMessage);
// set the progress to be horizontal
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
// reset the bar to the default value of 0
progressDialog.setProgress(0);
// convert the text value to a integer
int maximum = 100;
// set the maximum value
progressDialog.setMax(maximum);
// display the progressbar
progressDialog.show();  

如您所见,我的进度条位于底部。如何将此进度条的位置更改为页面的 3/4?我想移动那个位置会在中心和底部之间吗?也许我可以设置MarginTop,但是如何设置?

4

1 回答 1

2

尝试这样的事情:

// ...
progressDialog.getWindow().setGravity(Gravity.CENTER);
WindowManager.LayoutParams wmlp = progressDialog.getWindow().getAttributes();
wmlp.y = height / 4;
progressDialog.getWindow().setAttributes(wmlp);
progressDialog.setCancelable(false);
// ...

您在这样的方法中初始化heightint值(屏幕的高度)在哪里:onCreate

height = getResources().getDisplayMetrics().heightPixels;
于 2012-07-02T10:12:35.320 回答