本文整理匯總了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();
}
}