contentView); 如果创建PopupWindow的时候没有指定高宽,那么showAsDropDown默认只会向下弹出显示,这种情况有个最明显的缺点就是:弹窗口可能被屏幕截断,显示不全,所以需要使用到另外一个方法showAtLocation...calculatePopWindowPos(view, windowContentViewRoot); int xOff = 20;// 可以自己调整偏移 windowPos[0] -= xOff; popupwindow.showAtLocation
= null) { mPopupWindow.showAtLocation(parent, Gravity.NO_GRAVITY, location[0], location...= null) { mPopupWindow.showAtLocation(view, Gravity.NO_GRAVITY, location[0], location...= null) { mPopupWindow.showAtLocation(view, Gravity.NO_GRAVITY, location[0] - getWidth...} return this; } public CommonPopWindow showAtLocation(View anchor, int gravity, int...= null) { mPopupWindow.showAtLocation(anchor, gravity, x, y); } return this
初看其实很简单,根据A的位置和大小,算出PopupWindow的位置,调用showAtLocation方法即可实现在A正上方弹出。...; int[] location = new int[2]; v.getLocationOnScreen(location); popupWindow.showAtLocation...这里写图片描述 可以发现,我们的PopupWindow并没有跟随一起滚动,这是因为在调用showAtLocation的时候,PopupWindow的位置已经确定了,所以并不会跟着A的滚动而滚动。
sendMsgPopup = new SendMsgPopupWindow(NewsDetailsActivity.this); } //设置处于底部 sendMsgPopup.showAtLocation...// 评论框消息的同时把软键盘关闭 KeyBoardUtils.closeKeybord(editText, mContext); } public void showAtLocation...this.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED); // 在显示输入法之后调用,否则popupwindow会在窗口底层 super.showAtLocation
popupWindow.showAsDropDown(view, 0, -view.getHeight() - popupWindow.getHeight()); popupWindow.showAtLocation...location[1]; switch (type) { case TOP2TOP: popupWindow.showAtLocation...x, y); break; case TOP2BOTTOM: popupWindow.showAtLocation...view.getHeight()); break; case BOTTOM2TOP: // popupWindow.showAtLocation...(view, Gravity.CLIP_HORIZONTAL, 0, 0); popupWindow.showAtLocation(view, Gravity.NO_GRAVITY
而PopupWindow似乎就提供了showAsDropDown方法(请忽略showAtLocation,这边说的是相对于View显示),这~~就有点尴尬了。....); //又或者使用showAtLocation根据屏幕来定位 mWindow.showAtLocation(...); Gravity.LEFT(Gravity.START):相对于View左对齐;...Gravity.CENTER:在showAsDropDown()中是跟 Gravity.LEFT一样,在showAtLocation()中Gravity.CENTER才有效果 得到效果
最近发现了在Android N(Android 7.0,7.1)上Popwindow的一个位置显示问题,当指定PopupWindow高度为MATCH_PARENT时使用showAsDropDown或者是showAtLocation...mPopupWindow.setHeight(screenHeight - offsetY); // 重新设置 PopupWindow 的高度 } mPopupWindow.showAtLocation
} public void send(View source){ //set the location of PopupWindow popupWindow.showAtLocation
PopupWindow显示在这个控件的下方;而showAtLocation是相对于屏幕,可以通过设置Gravity来指定PopupWindow显示在屏幕的那个位置。...我们再来看showAtLocation: 因为这个方法是PopupWindow的显示相对于屏幕,所以传入的View也是只要这个屏幕的就可以,因为这个View的传入也只是为了拿到Window Token。...//这个方法最后还是等于调用了另外一个showAtLocation方法, //传入view只是为了拿到token //x,y同样是x和y轴的偏移值 public void showAtLocation(...:popupWindow.showAtLocation(view, Gravity.RIGHT | Gravity.BOTTOM, 0, 0); ?...如果我们设置为:popupWindow.showAtLocation(view, Gravity.TOP, 0, 0); ? 我们发现PopupWindow并没有在statusbar的上面。
我们再来看showAtLocation: 因为这个方法是PopupWindow的显示相对于屏幕,所以传入的View也是只要这个屏幕的就可以,因为这个View的传入也只是为了拿到Window Token。...//这个方法最后还是等于调用了另外一个showAtLocation方法, //传入view只是为了拿到token //x,y同样是x和y轴的偏移值 public void showAtLocation(...View parent, int gravity, int x, int y) { showAtLocation(parent.getWindowToken(), gravity, x, y);...} public void showAtLocation(IBinder token, int gravity, int x, int y){ ....... } 比如我们写入的代码是:popupWindow.showAtLocation...(view, Gravity.RIGHT | Gravity.BOTTOM, 0, 0); 如果我们设置为:popupWindow.showAtLocation(view, Gravity.TOP, 0
genderPopupWindow.dismiss(); } }); } genderPopupWindow.showAtLocation...mLevel = 0.4f; } setBackGroundLevel(mLevel); } @Override public void showAtLocation...(View parent, int gravity, int x, int y) { super.showAtLocation(parent, gravity, x, y);...waitPayP.prestWeChatOrder(amount, ordersn, subject); } }); orderListPayPop.showAtLocation
int[] location = new int[2]; v.getLocationOnScreen(location); //在控件上方显示 showAtLocation
ViewGroup.LayoutParams.WRAP_CONTENT); popupWindow.setAnimationStyle(R.style.Popupwindow);//包括进入和退出两个动画 popupWindow.showAtLocation...R.style.Popupwindow); int[] location = new int[2]; view.getLocationOnScreen(location); popupWindow.showAtLocation...关于PopupWindow的显示位置,它既提供了showAtLocation方法精确控制,也提供了showAsDropDown(view)方法简单控制。
showAtLocation(View parent, int gravity, int x, int y):将PopupWindow显示在指定父容器View内的指定位置。...showAtLocation(View parent, int gravity, int x, int y):将PopupWindow显示在指定父容器View内的指定位置。
null)); popupwindow.setOnDismissListener(new OnPopupDismissListener()); popupwindow.showAtLocation
R.style.AnimUp) .setViewOnclickListener(this) .create(); popupWindow.showAtLocation
效果图 ---- 内容补充 RelativeLayout rl_content = (RelativeLayout) findViewById(R.id.rl_content); popupWindow.showAtLocation...(rl_content, Gravity.CENTER, 0, 0); 补充: 显示还有一种方法, showAtLocation().
500, true); mPopupWindow.setBackgroundDrawable(new BitmapDrawable()); } mPopupWindow.showAtLocation
); // popupWindow.setOutsideTouchable(true); popupWindow.setFocusable(true); popupWindow.showAtLocation
Log.e("", "333 " + this.getWidth()); Log.e("", "333 " + (mLocation[1])); // 显示弹窗的位置 // showAtLocation...(view, popupGravity, mScreenWidth - LIST_PADDING // - (getWidth() / 2), mRect.bottom); showAtLocation
领取专属 10元无门槛券
手把手带您无忧上云