I need to show popup window directly above button. My button is placed inside scroll view, and popup always shown below button. Here is my code:
  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();
    }
}
But it is not work. Please hep me.

Change Gravity to Top and reset your coordinates according to your requirement.
infoPopup.showAtLocation(view, Gravity.TOP, 0, (int) view.getY());
When you have to show the popup, find out the location of the button in the screen, then use the showAtLocation() method as Prachi Said using Gravity.TOP and the x,y coordinates of the button on screen...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With