Android 底部工作表在工具提示内不工作,此弹出窗口显示在底部工作表后面
我有一个底部表单,我正在加载弹出窗口,但它没有显示在底部表单上。此弹出窗口显示在底部工作表后面Android 底部工作表在工具提示内不工作,此弹出窗口显示在底部工作表后面,android,popup,bottom-sheet,Android,Popup,Bottom Sheet,我有一个底部表单,我正在加载弹出窗口,但它没有显示在底部表单上。此弹出窗口显示在底部工作表后面 CustomTextView textView = (CustomTextView) layout.findViewById(R.id.info_disc); textView.setText(text, TextView.BufferType.SPANNABLE); final PopupWindow popup = new PopupWindow(context);
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
实际上是一个对话框
;与活动
窗口完全分离的窗口。PopupWindow
与错误的窗口关联,这就是为什么它显示在BottomSheetDialog
后面
传递给PopupWindow
的show*()
方法的视图
用于确定与PopupWindow
关联的窗口。在给定的代码段中:
popup.showAtLocation(layout, Gravity.TOP | Gravity.LEFT, p.right, p.top + 15);
layout
是膨胀的视图
用作PopupWindow
的内容,因此尚未附加到任何窗口,因此它不知道在底部表单对话框上方显示
解决方法是在调用时,只需传递当前附加到底部表单对话框的showAtLocation()
a视图
,任何视图
:
popup.showAtLocation(view, Gravity.TOP | Gravity.LEFT, p.right, p.top + 15);
底部工作表是BottomSheetDialog
还是BottomSheetDialogFragment
?这就是原因,因为这是一个与活动
完全独立的窗口。视图是否显示在活动
或对话框片段
的旁边?无论哪种情况,这都是您应该传递给showAtLocation()
,而不是layout
。我的活动是加载底部工作表,在显示弹出窗口的底部工作表中,当我调用弹出窗口时,它显示在底部工作表后面谢谢,@MikeM。这是工作,你可以把这个作为答案,我也会批准