我有一个底表,我正在加载弹出窗口,但它没有显示在底板上。此弹出窗口显示在底部工作表后面
CustomTextView textView = (CustomTextView) layout.findViewById(R.id.info_disc);
textView.setText(text, TextView.BufferType.SPANNABLE);
final PopupWindow popup = new PopupWindow(context);
popup.setContentView(layout);
DisplayMetrics displayMetrics = new DisplayMetrics();
context.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int width = displayMetrics.widthPixels;
popup.setWidth((int) (width - (view.getX() + view.getWidth() + ViewUtils.convertDpToPixel(12, context))));
popup.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
popup.setFocusable(true);
popup.setBackgroundDrawable(new BitmapDrawable());
Rect p = locateView(view);
popup.showAtLocation(layout, Gravity.TOP | Gravity.LEFT, p.right, p.top + 15);
在这种情况下,底板是一个BottomSheetDialogFragment
,它控制BottomSheetDialog
确实是一个Dialog
;一个与Activity
窗口完全分开的窗口。PopupWindow
与错误的窗口相关联,这就是为什么它显示在BottomSheetDialog
后面的原因。
传递给PopupWindow
show*()
方法的View
用于确定与哪个窗口相关联PopupWindow
。在给定的代码段中:
popup.showAtLocation(layout, Gravity.TOP | Gravity.LEFT, p.right, p.top + 15);
layout
是膨胀的View
作为PopupWindow
的内容,因此还没有附加到任何窗口,所以它不知道显示在BottomSheetDialog
上方。
解决方法是简单地传递showAtLocation()
一个View
,任何View
,当前在进行调用时附加到BottomSheetDialog
:
popup.showAtLocation(view, Gravity.TOP | Gravity.LEFT, p.right, p.top + 15);