gpt4 book ai didi

android - 工具提示内的 Bottom Sheet 无法正常工作,此弹出窗口显示在 Bottom Sheet 后面

转载 作者:行者123 更新时间:2023-12-03 10:12:02 24 4
gpt4 key购买 nike

我有一个 Bottom Sheet ,我正在加载弹出窗口,但它没有显示在 Bottom Sheet 中。该弹出窗口显示在 Bottom Sheet 格的后面

    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后面显示的原因。

传递给ViewPopupWindow方法的show*()用于确定与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);

关于android - 工具提示内的 Bottom Sheet 无法正常工作,此弹出窗口显示在 Bottom Sheet 后面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61288070/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com