展会信息港展会大全

Android开发中在屏幕任意位置显示对话框 x,y轴坐标
来源:互联网   发布日期:2015-10-03 11:40:01   浏览:2069次  

导读:下面是设置对话框x的偏移量。int marginLeft = 100;Window window = getDialog() getWindow();WindowManager LayoutParams wmlp =window getAttributes();wmlp gravity = Gravity LEFT;wmlp x = mar ...

下面是设置对话框x的偏移量。

int marginLeft = 100;

Window window = getDialog().getWindow();

WindowManager.LayoutParams wmlp =window.getAttributes();

wmlp.gravity = Gravity.LEFT;

wmlp.x = marginLeft;

Log.i(getTag(), "wmlp="+wmlp);

window.setAttributes(wmlp);

值得注意的是: 我们要看看WindowManager.LayoutParams的文档中关于x,y属性的说明:

/**

* X position for this window.With the default gravity it is ignored.

* When using {@link Gravity#LEFT} or {@link Gravity#START} or {@link Gravity#RIGHT} or

* {@link Gravity#END} it provides an offset from the given edge.

*/

@ViewDebug.ExportedProperty

public int x;

/**

* Y position for this window.With the default gravity it is ignored.

* When using {@link Gravity#TOP} or {@link Gravity#BOTTOM} it provides

* an offset from the given edge.

*/

@ViewDebug.ExportedProperty

public int y;

重要的两点就是:

(1)如果你需要设置x的值,那么需要将gravity设置有LEFT,START,RIGHT或者END。

(2)如果你需要设置y的值,那么需要将gravity设置成有TOP,BOTTOM。

上面的两点,如果你的对FrameLayout设置的margin不起作用了,可能也是需要遵守上面两点规则。

赞助本站

人工智能实验室

相关热词: 对话框 位置 Android

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港