android - PopupWindow 被截断到屏幕底部

标签 android android-popupwindow

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

有人知道为什么吗?

最佳答案

测量 View 然后设置高度解决了我的问题。

View view = LayoutInflater.from(mContext).inflate(R.layout.popupmenu_addphotos, null);
view.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
setHeight(view.getMeasuredHeight());

关于android - PopupWindow 被截断到屏幕底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59771672/

相关文章:

android - BluetoothDevice.aliasName 未解析的引用

android - 如何限制 TextView 在 Android 中仅允许使用字母数字字符

android - 在带有 alpha 的 Material Button 上设置 backgroundTint 在正常和按下状态下具有奇怪的视觉效果

Android 弹出窗口 : White background but keep shadow?

java - 安卓 : Approach of passing variable generated in click event of fragment and popup window to activity

android - 弹出窗口不显示

android - Android中如何创建弹出窗口(PopupWindow)

android - 我应该使用 PopupWindow 或 DialogFragment 来接受输入吗?

android - Android Studio 中 gradle 依赖与 java import 语句之间的区别

java - 在android中使用JSON解析数据