android对话框活动位置

android dialog activity position(android对话框活动位置)
本文介绍了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对话框活动位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How To Create a Rotating Wheel Control?(如何创建转轮控件?)
How to avoid restarting activity when orientation changes on Android(如何在 Android 上的方向更改时避免重新启动活动)
Screen orientation lock(屏幕方向锁定)
Strange behavior with android orientation sensor(android方向传感器的奇怪行为)
Android: Rotate image in imageview by an angle(Android:将imageview中的图像旋转一个角度)
Activity restart on rotation Android(旋转Android上的活动重启)