Android 如何更改进度对话框的位置?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3392256/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change the position of a progress dialog?
提问by oliverwhite
I'm developing an android app and need to know how to change the positioning of a progress dialog. I need it to be positioned at the bottom of the screen instead of at the center like it is by default.
我正在开发一个 android 应用程序,需要知道如何更改进度对话框的位置。我需要将它放置在屏幕底部而不是像默认情况下那样位于中心。
回答by Rich Schuler
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);
回答by Bobs
In addition to the other answers you can use LayoutParams.x or LayoutParams.y to provide an offset from the given edge. For Example:
除了其他答案之外,您还可以使用 LayoutParams.x 或 LayoutParams.y 来提供距给定边缘的偏移量。例如:
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. With the default gravity it is ignored. When using TOP or BOTTOM it provides an offset from the given edge.
此窗口的 Y 位置。在默认重力下,它被忽略。当使用 TOP 或 BOTTOM 时,它提供了从给定边缘的偏移量。
and about LayoutParams.x:
关于 LayoutParams.x:
X position for this window. With the default gravity it is ignored. When using LEFT or START or RIGHT or END it provides an offset from the given edge.
此窗口的 X 位置。在默认重力下,它被忽略。当使用 LEFT 或 START 或 RIGHT 或 END 时,它提供与给定边缘的偏移量。
回答by Samuel Robert
If you're using any custom theme for the ProgressDialog, Then you could add the below xml tag to the style in your style.xml file of the custom theme
如果您为 ProgressDialog 使用任何自定义主题,那么您可以将以下 xml 标记添加到自定义主题的 style.xml 文件中的样式
<item name="android:layout_gravity">bottom</item>
<item name="android:layout_gravity">bottom</item>
回答by matto1990
Adding android:gravity="bottom" to the outermost XML element in the layout might do it. Not sure if this moves the dialog or the contents of it.
将 android:gravity="bottom" 添加到布局中最外面的 XML 元素可能会做到这一点。不确定这是否会移动对话框或其内容。