下面是设置对话框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不起作用了,可能也是需要遵守上面两点规则。



更多相关文章

  1. Android开发之Activity(二)——启动模式和taskAffinity属性
  2. android:clipChildren属性的分析——是否剪裁子View
  3. Android 七种对话框使用
  4. ImageView的属性
  5. 【Android】Android自定义属性,attr format取值类型
  6. Android使用TextView,设置onClick属性无效解决办法
  7. Android自定义对话框列表

随机推荐

  1. Android(安卓)读取Bitmap的几种方式
  2. Android(安卓)JNI打印Log
  3. Android实现QQ图片说说照片选择效果
  4. 工具类之FragmentUtils
  5. Android开源项目:GifView——Android显示G
  6. Android(安卓)自定义View 性能分析学习
  7. html5开发全屏android软件
  8. 如何将Android(安卓)源码中编译出的apk进
  9. Android用yasea集成推流服务并实现美颜滤
  10. Android中View和ViewGroup事件分发拦截机