更改code进度的位置 [英] Change position of progressbar in code
本文介绍了更改code进度的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我的$ C $创建Ç我的活动进度条。 这是code:
I have a progress bar which I create in code my activity. This is code:
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?我想移动的地位将中部和底部之间?也许我可以setMarginTop,但如何?
As you can see position my progressbar is bottom. How I can change position this progressbar to 3/4 of my page? I want to move that position will be between center and bottom? Maybe can I setMarginTop, but how?
推荐答案
尝试是这样的:
// ...
progressDialog.getWindow().setGravity(Gravity.CENTER);
WindowManager.LayoutParams wmlp = progressDialog.getWindow().getAttributes();
wmlp.y = height / 4;
progressDialog.getWindow().setAttributes(wmlp);
progressDialog.setCancelable(false);
// ...
其中,高度
是 INT
值(屏幕的高度),你在<$ C初始化$ C>的onCreate 的方法是这样的:
Where height
is an int
value(the height of the screen) that you initialize in the onCreate
method like this:
height = getResources().getDisplayMetrics().heightPixels;
这篇关于更改code进度的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文