[英]Android. How to show popup window directly above button
我需要在按鈕上方直接顯示彈出窗口。 我的按鈕位於滾動視圖中,彈出窗口始終顯示在按鈕下方。 這是我的代碼:
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.