【发布时间】:2019-06-03 07:13:35
【问题描述】:
我需要在按钮上方直接显示弹出窗口。我的按钮放置在滚动视图内,并且弹出窗口始终显示在按钮下方。这是我的代码:
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();
}
}
【问题讨论】:
-
你在函数中传递的视图是什么?使用 View 的 getLocationOnScreen() 方法并传递一个 int 数组来获取屏幕中的 Location,然后使用 showAtLocation() 方法中的那些,在该函数中传递 Button...
-
并举例说明您在此处尝试实现的目标,设计或其他内容
标签: java android scrollview popupwindow