【发布时间】:2020-04-18 11:05:52
【问题描述】:
我有一个底页我正在加载弹出窗口,但它没有显示在底页上。此弹出窗口显示在底部工作表后面
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);
【问题讨论】:
-
您的底页是
BottomSheetDialog还是BottomSheetDialogFragment? -
BottomSheetDialogFragment
-
这就是原因,因为这是与
Activity完全分开的窗口。view是显示在Activity或BottomSheetDialogFragment旁边吗?无论哪种情况,这都是您应该传递给showAtLocation(),而不是layout。 -
我有活动加载底部表,底部表内显示弹出窗口,当我调用弹出窗口时,它显示在底部表后面
-
是的,没关系,你只需要传递
popup.showAtLocation()一个附加到BottomSheetDialog窗口的View,而不是layout,因为这可能是你在上面膨胀的.如果view在locateView(view)调用中确实在BottomSheetDialogFragment中,则将其传递给:popup.showAtLocation(view, ...。
标签: android popup bottom-sheet