【发布时间】:2017-12-05 04:43:23
【问题描述】:
嗨,我有一个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())));
【问题讨论】:
-
你在哪里调用 showPopUpWindow 方法
-
@Nilu textview 我在 textview setOnClickListener 方法中调用
-
请与问题分享该代码
-
请提供minimal reproducible example。共享无法正确查看的屏幕截图也是无用的。提供更高分辨率的屏幕截图。
-
@Nilu 请检查我更新了
标签: java android popupwindow