簡體   English   中英

Android 彈出窗口未顯示在正確位置

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM