关于点击编辑头像后 dialog 的问题
来源:3-8 用户管理—CircleImageView圆形头像

慕标5491943
2018-06-22
是这样的,老师视频中 dialog 初始化为
dialog = new CustomDialog(getActivity(),0,0,R.layout.dialog_photo,R.style.pop_anim_style, Gravity.BOTTOM,0);
这里的宽和高都为0? 我不懂为什么老师视频里就可以正常显示dialog ,而我的就是没有,我只能调宽和高来让dialog显示出来。
有什么方法可以解决这个问题?
我上网查了下 在fragment下获取屏幕宽和高的方法 貌似没找到,只有在Activity下获取的方法。
写回答
3回答
-
叶为正啊
2018-10-13
照着源码改下CustomDialog类就OK了。
以下源码:
//定义模板 public CustomDialog(@NonNull Context context, int layout, int style) { this(context, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT, layout, style, Gravity.CENTER); } //定义属性 public CustomDialog(@NonNull Context context, int width, int height, int layout, int style, int gravity, int anim) { super(context, style); //设置属性 setContentView(layout); Window window = getWindow(); WindowManager.LayoutParams layoutParams = window.getAttributes(); layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT; layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT; layoutParams.gravity = gravity; window.setAttributes(layoutParams); window.setWindowAnimations(anim); } //实例 public CustomDialog(Context context, int width, int height, int layout, int style, int gravity) { this(context, width, height, layout, style, gravity,R.style.pop_anim_style); }
10 -
12313凯皇
2018-09-11
+1 我也是这样
00 -
刘某人
2018-08-08
下载一下源码,在源码里拷贝一下Dialog再次调用
00
相似问题