代码之家  ›  专栏  ›  技术社区  ›  Jack

弹出窗口显示屏幕的底部边界

  •  1
  • Jack  · 技术社区  · 6 年前

    当最右边的项目弹出窗口得到调整,以在屏幕内。

    但当项目接近屏幕底部时,弹出窗口被裁剪(部分在屏幕外)。

    怎么修这个?

    PopupWindow mDropDownMenu= new PopupWindow(list, WRAP_CONTENT, WRAP_CONTENT);
    
    mDropDownMenu.showAsDropDown(aView);
    

    文档中提到了showAsDropDown(视图锚定)

     * Display the content view in a popup window anchored to the bottom-left
     * corner of the anchor view. If there is not enough room on screen to show
     * the popup in its entirety, this method tries to find a parent scroll
     * view to scroll. If no parent scroll view can be scrolled, the
     * bottom-left corner of the popup is pinned at the top left corner of the
     * anchor view.
     *
    

    但它总是固定在左下角,不要往左上。

    2 回复  |  直到 6 年前
        1
  •  4
  •   Jack    6 年前

    原来我 必须 设置下拉菜单高度以避免此问题

    List<DropDownListItem> items;
    
    dropDown.setHeight( toPixels( 30 * items.size() ) );
    
        2
  •  1
  •   Bohsen    6 年前

    PopupWindow .

    ...
    private fun showPopupWindow() {
            val popupView = layoutInflater.inflate(R.layout.standard_popup_window, null)
            popupView.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
            PopupWindow(popupView, popupView.measuredWidth, popupView.measuredHeight).apply {
                setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
                isTouchable = true
                isFocusable = true
                overlapAnchor = true
                width = popupView.measuredWidth
                height = popupView.measuredHeight
                contentView = popupView
                showAsDropDown(fragment_person_details__description)
            }
    ...