[英]Android Popup Window is not showing in correct location
您好我有一個FlowLayout
顯示的列表textViews
。 當我單擊textview
我必須在textview
下方顯示PopWindow
。但它沒有顯示在正確的位置。
public void showPopUpWindow(View view, int position) {
LinearLayout linearLayout = (LinearLayout) LayoutInflater.from(this).inflate(R.layout.layout_attributes_popup, null);
FlowLayout flowLayout = linearLayout.findViewById(R.id.flow_layout);
BubbleLayout bubbleLayout = linearLayout.findViewById(R.id.bubble_layout);
prepareAttributes(flowLayout);
PopupWindow mPopupWindow = BubbleHelper.create(this, linearLayout);
mPopupWindow.setFocusable(true);
mPopupWindow.update();
if (mPopupWindow != null) {
mPopupWindow.dismiss();
}
Rect rc = new Rect();
view.getWindowVisibleDisplayFrame(rc);
int[] xy = new int[2];
view.getLocationInWindow(xy);
rc.offset(xy[0], xy[1]);
//int[] location = new int[2];
// view.getLocationInWindow(location);
bubbleLayout.setArrowPosition(rc.left);
//mPopupWindow.showAsDropDown(view, 0, 0);
mPopupWindow.showAtLocation(view, Gravity.NO_GRAVITY, rc.left, rc.top);
}
點擊方法:
textView.setOnClickListener(view1 -> ((RichElementSelectionActivity) mContext).
showPopUpWindow(view1, mFlowLayout.indexOfChild((View) view1.getParent())));
我遇到了同樣的問題,所以這就是我在kotlin
解決的kotlin
view
是您想用作彈出窗口錨點的任何視圖
val popupView: View = layoutInflater.inflate(R.layout.popup_view_order_status, null)
val popupWindow = PopupWindow(popupView,
FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT)
popupWindow.isFocusable = true
popupWindow.setBackgroundDrawable(ColorDrawable())
val location = IntArray(2)
view.getLocationOnScreen(location)
popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, location[0], location[1])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.