android dialog activity position(android对话框活动位置)
问题描述
我使用 android:theme="@android:style/Theme.Dialog" 创建了一个非最大化活动,使其看起来像一个对话框.我需要更改活动在屏幕上的位置,但我没有找到如何执行此操作...
I created an non-maximized activity using android:theme="@android:style/Theme.Dialog" to make it looks like a dialog. I need to change the position of the activity on screen but I didn't find how to do this...
推荐答案
要改变位置(主题设置为Theme.Dialog
),可以覆盖重力、大小和坐标活动装饰视图附加到窗口后的 LayoutParams.这是一个例子:
To change the position (with the theme set to Theme.Dialog
), you can override the gravity, size and coordinates of the LayoutParams of your activity's decor view after it has been attached to the window. Here's an example:
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
View view = getWindow().getDecorView();
WindowManager.LayoutParams lp = (WindowManager.LayoutParams) view.getLayoutParams();
lp.gravity = Gravity.LEFT | Gravity.TOP;
lp.x = 10;
lp.y = 10;
lp.width = 300;
lp.height = 300;
getWindowManager().updateViewLayout(view, lp);
}
这篇关于android对话框活动位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:android对话框活动位置


- Android - 拆分 Drawable 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01