本文整理汇总了Java中android.view.ViewGroup.measure方法的典型用法代码示例。如果您正苦于以下问题:Java ViewGroup.measure方法的具体用法?Java ViewGroup.measure怎么用?Java ViewGroup.measure使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.ViewGroup
的用法示例。
在下文中一共展示了ViewGroup.measure方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: measureViewGroupHeight
import android.view.ViewGroup; //导入方法依赖的package包/类
private static int measureViewGroupHeight(ViewGroup viewGroup) {
View parent = (View) viewGroup.getParent();
int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(
parent.getMeasuredWidth() - parent.getPaddingLeft() - parent.getPaddingRight(),
View.MeasureSpec.AT_MOST);
int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
viewGroup.measure(widthMeasureSpec, heightMeasureSpec);
return viewGroup.getMeasuredHeight();
}
示例2: show
import android.view.ViewGroup; //导入方法依赖的package包/类
public void show(Context content,View locationView,String[] menuLabelArray,OnPopMultiMenuClick onPopMultiMenuClick){
try {
//check
if(menuLabelArray==null || menuLabelArray.length<1){
throw new RuntimeException(" menu label can not be empty ");
}
// ready
LayoutInflater layoutInflater=LayoutInflater.from(content);
mOnPopMultiMenuClick = onPopMultiMenuClick;
// 如果只有一个,则把divider删除掉
ViewGroup popupView =(ViewGroup) layoutInflater.inflate(R.layout.udesk_multi_horizontal_popmenu, null);
// 把菜单都添加进去
addChildView(popupView,layoutInflater,menuLabelArray);
setContentView(popupView);
// 测绘并定位
popupView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
int popupWidth = popupView.getMeasuredWidth();
int popupHeight = popupView.getMeasuredHeight();
setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
setHeight(popupHeight);
//显示出来
int[] location = new int[2];
locationView.getLocationOnScreen(location);
showAtLocation(locationView, Gravity.NO_GRAVITY , /*location[0]*/(location[0]+locationView.getWidth()/2)-popupWidth/2,
location[1]-popupHeight/*location[1]- getHeight()*/);
} catch (RuntimeException e) {
e.printStackTrace();
}
}