【问题标题】:Unable to show PopUpWindow under specific layout Android无法在特定布局Android下显示PopUpWindow
【发布时间】:2017-09-27 22:36:50
【问题描述】:

单击按钮时关闭软键盘后,我想在LinearLayout 下显示一个PopUpWindow。

这就是我要找的

当用户单击按钮时,键盘隐藏,然后弹出窗口显示在LinearLayout(最初的键盘区域)下。喜欢下面这张图

我试试这个代码:

button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //hide the keyboard
            InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);

            LinearLayout bottomBar = (LinearLayout)findViewById(R.id.bottomBar);

            LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
            View popupView = inflater.inflate(R.layout.popup_window, null);

            // create the popup window
            int width = LinearLayout.LayoutParams.MATCH_PARENT;
            int height = LinearLayout.LayoutParams.WRAP_CONTENT;
            boolean focusable = true; dismiss it
            final PopupWindow popupWindow = new PopupWindow(popupView, width, height, focusable);

            // show the popup window
            popupWindow.showAtLocation(bottomBar, Gravity.BOTTOM, 0, 0);
       }
   }

但是以这样的方式结束PopUpWindow

包含按钮的LinearLayout,隐藏键盘时进入屏幕底部,PopUpWindow显示在LinearLayout之上,因此它变得不可见。如下图:

那么我怎样才能得到像第一张图片一样的欲望行为呢?PopUpWindow 在键盘隐藏后显示在LinearLayout 下。

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    您为什么要尝试使用弹出窗口来执行此操作。我建议你保持简单的布局。这个布局将包含两个视图(带有按钮的布局和它下面的弹出布局)。只需在屏幕底部添加此布局,并在需要时设置弹出布局可见性 VISIBLE/GONE 的可见性。您可以通过以下方式在显示或隐藏弹出布局时添加动画: Show/Hide View using Slide Up and Down Animation

    【讨论】:

    • 我试过了。但整个布局正在移动以弹出布局。但没有顺利显示弹出窗口
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多