PopupWindow会很好地膨胀,直到它被截断在屏幕底部附近为止。任何人都知道当它靠近屏幕底部时如何向上膨胀?
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);
}
任何人都知道为什么吗?
我替换了下面的线
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();
}