Android(安卓)PopulWindow创建与定位
16lz
2022-05-27
创建一个PopulWindow
if (popupWindow != null && popupWindow.isShowing()) {popupWindow.dismiss();return;}int popWidth = Common.dip2px(this, 120);View contentView = getLayoutInflater().inflate(R.layout.pop, null);WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);popupWindow = new PopupWindow(contentView, popWidth,LayoutParams.WRAP_CONTENT, true);popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));int xOff = windowManager.getDefaultDisplay().getWidth() / 2- popupWindow.getWidth() / 2;popupWindow.showAsDropDown(view, xOff, 0);popupWindow.update();
定位:
populWindow.showAsDropDown(view)——> 以view的左下角作为参照,位于view的下方
populWindow.showAsDropDown(view,xoff,yoff)——> 以view 的左下角作为参照,同时可以设置偏移
mPop.showAtLocation(parent, Gravity.CENTER, 0, 0); 以parent为参照物。
更多相关文章
- Android(安卓)PDF开发:android-pdfview
- Android作为服务端,PC推送消息
- android自定义控件:可旋转View:可作为ImageView、ImageButton
- Android作为SocketServer以及手机IP问题
- A20启动LUNCH选项修改
- 【android】与pc机进行UDP通信
- 解决 android 在sd卡新建文件后需要重启才能找到
- Android耳机按键监听
- Android(安卓)中动态提取图片中颜色作为主题色