Android在屏幕任意位置显示对话框

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

1int marginLeft = 100; 2 Window window = getDialog().getWindow(); 3 WindowManager.LayoutParams wmlp =window.getAttributes(); 4 wmlp.gravity = Gravity.LEFT; 5 wmlp.x = marginLeft; 6 Log.i(getTag(), "wmlp="+wmlp); 7 window.setAttributes(wmlp);

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

1/** 2 * X position for this window. With the default gravity it is ignored. 3 * When using {@link Gravity#LEFT} or {@link Gravity#START} or {@link Gravity#RIGHT} or 4 * {@link Gravity#END} it provides an offset from the given edge. 5 */ 6 @ViewDebug.ExportedProperty 7 public int x; 8 9 /** 10 * Y position for this window. With the default gravity it is ignored. 11 * When using {@link Gravity#TOP} or {@link Gravity#BOTTOM} it provides 12 * an offset from the given edge. 13 */ 14 @ViewDebug.ExportedProperty 15 public int y;

重要的两点就是:

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

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

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

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

SpringBoot整合Redis乱码原因及解决方案

问题描述:springboot使用springdataredis存储数据时乱码rediskey/value出现\\xAC\\xED\\x00\\x05t\\x00\\x05问题分析:查看RedisTemplate类!(https://oscimg.oschina.net/oscnet/0a85565fa

mysql设置时区

mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0