安卓如何在按钮正上方显示弹出窗口

时间:2019-06-03 07:13:35

标签: java android scrollview popupwindow

我需要在按钮上方直接显示弹出窗口。我的按钮位于滚动视图中,弹出窗口始终显示在按钮下方。这是我的代码:

  private void showPopup(View view, String text) {
    if (infoPopup == null) {
        LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
        View popupView = layoutInflater.inflate(R.layout.popup_credit_request_passport, null);
        TextView tvPopupText = popupView.findViewById(R.id.tv_popup_text);
        tvPopupText.setMovementMethod(new ScrollingMovementMethod());
        tvPopupText.setText(text);
        FrameLayout flBackground = popupView.findViewById(R.id.fl_background);
        flBackground.setBackground(new BubbleDrawable(getContext(), R.color.azure, 16, 16, 8));

        infoPopup = new PopupWindow(popupView,
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        infoPopup.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        infoPopup.setOutsideTouchable(true);

        infoPopup.showAtLocation(view, Gravity.TOP, (int) view.getX(), (int) view.getY());

    } else {
        dismissInfoPopup();
    }
}

但这是行不通的。请帮我 enter image description here

2 个答案:

答案 0 :(得分:1)

重力设为顶部,然后根据需要重置坐标。

ssh ubuntu@POD_IP
mkdir new_file
ls 
  new_file
reboot

答案 1 :(得分:1)

当您必须显示弹出窗口时,找出按钮在屏幕上的位置,然后将showAtLocation()方法用作 Prachi ,使用Gravity.TOP和{屏幕上按钮的{1}} ...