【问题标题】:Bottom sheet inside the tooltip not working , This popup is showing behind the bottom sheet工具提示内的底部工作表不起作用,此弹出窗口显示在底部工作表后面
【发布时间】: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 是显示在 ActivityBottomSheetDialogFragment 旁边吗?无论哪种情况,这都是您应该传递给showAtLocation(),而不是layout
  • 我有活动加载底部表,底部表内显示弹出窗口,当我调用弹出窗口时,它显示在底部表后面
  • 是的,没关系,你只需要传递popup.showAtLocation() 一个附加到BottomSheetDialog 窗口的View,而不是layout,因为这可能是你在上面膨胀的.如果viewlocateView(view) 调用中确实在BottomSheetDialogFragment 中,则将其传递给:popup.showAtLocation(view, ...

标签: android popup bottom-sheet


【解决方案1】:

在这种情况下,底部工作表是BottomSheetDialogFragment,它控制的BottomSheetDialog确实是Dialog;与Activity 的窗口完全分开的窗口。 PopupWindow 关联了错误的窗口,这就是它显示在 BottomSheetDialog 后面的原因。

传递给PopupWindowshow*() 方法的View 用于确定将PopupWindow 与哪个窗口关联。在给定的 sn-p 中:

popup.showAtLocation(layout, Gravity.TOP | Gravity.LEFT, p.right, p.top + 15);

layoutView 膨胀以充当PopupWindow 的内容,因此尚未附加到任何窗口,因此它不知道显示在BottomSheetDialog 上方。

解决方法是在调用时简单地将showAtLocation() 传递给View,任何View,当前附加到BottomSheetDialog

popup.showAtLocation(view, Gravity.TOP | Gravity.LEFT, p.right, p.top + 15);

【讨论】:

    猜你喜欢
    • 2020-12-11
    • 2015-09-07
    • 2020-07-01
    • 2015-06-30
    • 2018-10-07
    • 1970-01-01
    • 2022-11-30
    • 1970-01-01
    • 2020-07-19
    相关资源
    最近更新 更多