机器人对话活动位置机器人、位置

2023-09-12 04:55:10 作者:一身祖宗味

我创建采用了android的非最大化的活动:主题=@安卓风格/ 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);
}