[英]How to get height of Popup after it is set to wrap_content?
Helo, 喂,
I've got this popup: 我有这个弹出窗口:
// Inflate the popup_layout.xml
LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.popup);
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View layout = layoutInflater.inflate(R.layout.day_popup_date, viewGroup);
layout.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
int popupWidth = width;
final int popupHeight = height;
// Creating the PopupWindow
final PopupWindow popup = new PopupWindow(context);
popup.setContentView(layout);
popup.setWidth(popupWidth);
popup.setHeight(ListPopupWindow.WRAP_CONTENT);
popup.setFocusable(false);
As you see, popup.setHeight(ListPopupWindow.WRAP_CONTENT); 如您所见,popup.setHeight(ListPopupWindow.WRAP_CONTENT); is set to wrap content.
设置为包装内容。
But I want enlarge the popup to 600px if the size is smaller than 100px. 但是,如果尺寸小于100px,我想将弹出窗口扩大到600px。
How can I do that? 我怎样才能做到这一点?
Thanks :-) 谢谢 :-)
简单地写...
popup.setHeight(600);
Finally got it: 终于明白了:
ViewTreeObserver vto = layout.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if(layout.getMeasuredHeight()> 0){
layout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
int heightmeasured = layout.getMeasuredHeight();
if(heightmeasured < popupHeight) {
popup.update(popupWidth, popupHeight);
}
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.