安卓.如何在按钮正上方显示弹出窗口 [英] Android. How to show popup window directly above button

查看:78
本文介绍了安卓.如何在按钮正上方显示弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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();
    }
}

但这不行.请帮我.

推荐答案

Change Gravity to Top 并根据您的要求重置您的坐标.

Change Gravity to Top and reset your coordinates according to your requirement.

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

这篇关于安卓.如何在按钮正上方显示弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆