Android在屏幕任意位置显示对话框
生活随笔
收集整理的這篇文章主要介紹了
Android在屏幕任意位置显示对话框
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
為什么80%的碼農都做不了架構師?>>> ??
下面是設置對話框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.ExportedPropertypublic 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.ExportedPropertypublic int y;
重要的兩點就是:
?(1)如果你需要設置x的值,那么需要將gravity設置有LEFT,START,RIGHT或者END。
? (2)如果你需要設置y的值,那么需要將gravity設置成有TOP,BOTTOM。
上面的兩點,如果你的對FrameLayout設置的margin不起作用了,可能也是需要遵守上面兩點規則。
轉載于:https://my.oschina.net/banxi/blog/102995
總結
以上是生活随笔為你收集整理的Android在屏幕任意位置显示对话框的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: django的settings中几个st
- 下一篇: 解决LiteIDE 中的error pr