为什么安卓popupwindow showAsDropDown offsetx是不是有效? [英] Why android popupwindow showAsDropDown offsetx is not effective?
问题描述
popupWindow.showAsDropDown(morebutton, xOffset, yOffset);
不管xOffset的值,在弹出是在屏幕显示的右侧
No matter the value of xOffset, the popup is on the right side of the screen display
final PopupWindow popupWindow = new PopupWindow(DashboardActivity.applicationContext);
LayoutInflater inflater = (LayoutInflater) DashboardActivity.applicationContext.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
popupWindow.setFocusable(true);
popupWindow.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
popupWindow.setContentView(view);
popupWindow.setBackgroundDrawable(new ColorDrawable(
android.graphics.Color.TRANSPARENT));
popupWindow.showAsDropDown(morebutton, **-220**, -40);
不管我怎么设置的值offsetX,他是在屏幕显示的右侧
No matter what I set the value offsetX, he is on the right side of the screen display
推荐答案
PopupWindow
试图调整你的内容查看
来你的锚
的 Gravity.TOP | Gravity.START
默认(左上角)。如果没有留给你的内容查看空间
它被抵消,以适应屏幕,这可能是为什么它停留在你右手边的。
PopupWindow
tries to align your contentView
to your anchor
's Gravity.TOP | Gravity.START
(top left corner) by default. If there is no space left for your contentView
it gets offset to fit on the screen, which is probably why it stays on your right side.
以下xOffset将调整内容查看
你的锚
的右上角:
The following xOffset will align the contentView
at your anchor
's top right corner:
view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
int xOffset = -(view.getMeasuredWidth() - morebutton.getWidth());
popupWindow.showAsDropDown(morebutton, xOffset, 0);
您可能想是这样的:
popupWindow.showAsDropDown(morebutton, xOffset - 220, -40);
这篇关于为什么安卓popupwindow showAsDropDown offsetx是不是有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!