需要根据屏幕设置PopupWindow位置

时间:2018-10-22 04:53:00

标签: android android-layout popupwindow popupmenu android-popupwindow

我想将PopupWindow设置为与屏幕相同。需要将 PopupWindow箭头消息更多按钮设置为相反的相同方向。

LayoutInflater inflater = (LayoutInflater)
getSystemService(LAYOUT_INFLATER_SERVICE);

View customView = inflater.inflate(R.layout.popup_chat_options, null);
mPopupWindow = new PopupWindow(
customView,
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
mPopupWindow.setAnimationStyle(R.style.CustomAnimationTopToBottom);
mPopupWindow.setOutsideTouchable(true);
mPopupWindow.setFocusable(true);
mPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

View view_popup_notification = customView.findViewById(R.id.view_popup_notification);

final View view = mPopupWindow.getContentView();
view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);

mPopupWindow.showAsDropDown(anchorView,
0,
-(anchorView.getMeasuredHeight() + customView.getMeasuredHeight()),
(from == 1) ? Gravity.NO_GRAVITY : Gravity.NO_GRAVITY);

enter image description here

0 个答案:

没有答案