您好我有FlowLayout
来显示textViews
的列表。当我点击textview
时,我必须在PopWindow
下面显示textview
。但是它没有显示在正确的位置。
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);
}
OnClick方法:
textView.setOnClickListener(view1 -> ((RichElementSelectionActivity) mContext).
showPopUpWindow(view1, mFlowLayout.indexOfChild((View) view1.getParent())));
答案 0 :(得分:0)
我遇到了同样的问题,所以这就是我在 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])