[英]Android. How to show popup window directly above button
I need to show popup window directly above button. 我需要在按钮上方直接显示弹出窗口。 My button is placed inside scroll view, and popup always shown below button.
我的按钮位于滚动视图中,弹出窗口始终显示在按钮下方。 Here is my code:
这是我的代码:
private void showPopup(View view, String text) {
if (infoPopup == null) {
LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
View popupView = layoutInflater.inflate(R.layout.popup_credit_request_passport, null);
TextView tvPopupText = popupView.findViewById(R.id.tv_popup_text);
tvPopupText.setMovementMethod(new ScrollingMovementMethod());
tvPopupText.setText(text);
FrameLayout flBackground = popupView.findViewById(R.id.fl_background);
flBackground.setBackground(new BubbleDrawable(getContext(), R.color.azure, 16, 16, 8));
infoPopup = new PopupWindow(popupView,
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
infoPopup.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
infoPopup.setOutsideTouchable(true);
infoPopup.showAtLocation(view, Gravity.TOP, (int) view.getX(), (int) view.getY());
} else {
dismissInfoPopup();
}
}
将“ 重力”更改为“顶部”,然后根据需要重置坐标。
infoPopup.showAtLocation(view, Gravity.TOP, 0, (int) view.getY());
当您必须显示弹出窗口时,找出按钮在屏幕上的位置,然后使用Gravity.TOP
和按钮在屏幕上的x,y coordinates
,如Prachi Said一样使用Gravity.TOP
showAtLocation()
方法...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.