PopupWindow被截断到屏幕底部

问题描述 投票:0回答:1

PopupWindow会很好地膨胀,直到它被截断在屏幕底部附近为止。任何人都知道当它靠近屏幕底部时如何向上膨胀?

enter image description here

public SelectBucketMenu(Context context) {
        super(context);
        this.mContext = context;

        setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        setOutsideTouchable(true);
        setFocusable(true);
        //Need set windowlayout for API 19 otherwise window won't appear
        setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

        setupView();
    }

    private void setupView(){
        View view = LayoutInflater.from(mContext)
                .inflate(R.layout.popupmenu_selectbucket, null);
        ButterKnife.bind(this, view);
        setContentView(view);
    }

任何人都知道为什么吗?

android android-popupwindow
1个回答
0
投票

我替换了下面的线

setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

with

setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT, 0);

并通过调用setHeight方法设置弹出高度。

最终代码如下:

public SelectBucketMenu(Context context) {
    super(context);
    this.mContext = context;

    setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    setOutsideTouchable(true);
    setFocusable(true);
    //Need set windowlayout for API 19 otherwise window won't appear
    setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT, 0);
    setHeight((int)mContext.getResources().getDimension(R.dimen.bucket_menu_height));
    setupView();
}
© www.soinside.com 2019 - 2024. All rights reserved.