简体   繁体   English

如何更改进度对话框的位置?

[英]How to change the position of a progress dialog?

I'm developing an android app and need to know how to change the positioning of a progress dialog. 我正在开发一个Android应用程序,需要知道如何更改进度对话框的位置。 I need it to be positioned at the bottom of the screen instead of at the center like it is by default. 我需要将其放置在屏幕底部,而不是默认情况下的中央位置。

You can call ProgressDialog#getWindow#setGravity(...) to change the gravity. 您可以调用ProgressDialog#getWindow#setGravity(...)来更改重力。

So: 所以:

ProgressDialog dialog = ProgressDialog.show(AContext, "Test", "On the bottom");
                dialog.getWindow().setGravity(Gravity.BOTTOM);

In addition to the other answers you can use LayoutParams.x or LayoutParams.y to provide an offset from the given edge. 除了其他答案,您还可以使用LayoutParams.x或LayoutParams.y提供与给定边的偏移量。 For Example: 例如:

progressDialog = ProgressDialog.show(this, "Title","Text");

progressDialog.getWindow().setGravity(Gravity.TOP);
LayoutParams params = progressDialog.getWindow().getAttributes();
params.y = 100;
progressDialog.getWindow().setAttributes(params);

And it is good for you to know about LayoutParams.y: 这对您了解LayoutParams.y很有帮助:

Y position for this window. 该窗口的Y位置。 With the default gravity it is ignored. 使用默认重力,它将被忽略。 When using TOP or BOTTOM it provides an offset from the given edge. 当使用TOP或BOTTOM时,它提供给定边的偏移量。

and about LayoutParams.x: 关于LayoutParams.x:

X position for this window. 此窗口的X位置。 With the default gravity it is ignored. 使用默认重力,它将被忽略。 When using LEFT or START or RIGHT or END it provides an offset from the given edge. 当使用LEFT或START或RIGHT或END时,它将提供给定边的偏移量。

如果对ProgressDialog使用任何自定义主题,则可以将以下xml标记添加到自定义主题的style.xml文件中的样式中

<item name="android:layout_gravity">bottom</item>

Adding android:gravity="bottom" to the outermost XML element in the layout might do it. 将android:gravity =“ bottom”添加到布局中最外层的XML元素可能会做到这一点。 Not sure if this moves the dialog or the contents of it. 不确定是否移动对话框或对话框的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM