本文整理匯總了Java中android.view.View.MeasureSpec.makeMeasureSpec方法的典型用法代碼示例。如果您正苦於以下問題:Java MeasureSpec.makeMeasureSpec方法的具體用法?Java MeasureSpec.makeMeasureSpec怎麽用?Java MeasureSpec.makeMeasureSpec使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.view.View.MeasureSpec
的用法示例。
在下文中一共展示了MeasureSpec.makeMeasureSpec方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: measureScrapChild
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
private void measureScrapChild(View child, int position, int widthMeasureSpec) {
ListView.LayoutParams p = (ListView.LayoutParams) child.getLayoutParams();
if (p == null) {
p = new ListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT, 0);
child.setLayoutParams(p);
}
//XXX p.viewType = mAdapter.getItemViewType(position);
//XXX p.forceAdd = true;
int childWidthSpec = ViewGroup.getChildMeasureSpec(widthMeasureSpec,
mDropDownList.getPaddingLeft() + mDropDownList.getPaddingRight(), p.width);
int lpHeight = p.height;
int childHeightSpec;
if (lpHeight > 0) {
childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight, MeasureSpec.EXACTLY);
} else {
childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
}
child.measure(childWidthSpec, childHeightSpec);
}
示例2: onMeasure
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
protected void onMeasure(int i, int i2) {
if (this.adapter == null) {
super.onMeasure(i, i2);
return;
}
int childCount = getChildCount();
int makeMeasureSpec = MeasureSpec.makeMeasureSpec(R.getScreenWidth(getContext()),
1073741824);
int i3 = 0;
int i4 = 0;
while (i3 < childCount) {
View childAt = getChildAt(i3);
childAt.measure(makeMeasureSpec, 0);
int measuredHeight = childAt.getMeasuredHeight();
if (measuredHeight <= i4) {
measuredHeight = i4;
}
i3++;
i4 = measuredHeight;
}
i4 = MeasureSpec.makeMeasureSpec(i4, 1073741824);
super.onMeasure(makeMeasureSpec, i4);
for (measuredHeight = 0; measuredHeight < childCount; measuredHeight++) {
getChildAt(measuredHeight).measure(makeMeasureSpec, i4);
}
}
示例3: onMeasure
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
boolean textVisible = hasText();
if (textVisible && this.mSavedPaddingLeft >= 0) {
super.setPadding(this.mSavedPaddingLeft, getPaddingTop(), getPaddingRight(), getPaddingBottom());
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int oldMeasuredWidth = getMeasuredWidth();
int targetWidth = widthMode == Integer.MIN_VALUE ? Math.min(widthSize, this.mMinWidth) : this.mMinWidth;
if (widthMode != 1073741824 && this.mMinWidth > 0 && oldMeasuredWidth < targetWidth) {
super.onMeasure(MeasureSpec.makeMeasureSpec(targetWidth, 1073741824), heightMeasureSpec);
}
if (!textVisible && this.mIcon != null) {
super.setPadding((getMeasuredWidth() - this.mIcon.getBounds().width()) / 2, getPaddingTop(), getPaddingRight(), getPaddingBottom());
}
}
示例4: measureScrapChild
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
private void measureScrapChild(View child, int position, int widthMeasureSpec) {
int childHeightSpec;
LayoutParams p = (LayoutParams) child.getLayoutParams();
if (p == null) {
p = new LayoutParams(-1, -2, 0);
child.setLayoutParams(p);
}
p.viewType = this.mAdapter.getItemViewType(position);
p.forceAdd = true;
int childWidthSpec = ViewGroup.getChildMeasureSpec(widthMeasureSpec, this.mListPadding
.left + this.mListPadding.right, p.width);
int lpHeight = p.height;
if (lpHeight > 0) {
childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight, 1073741824);
} else {
childHeightSpec = MeasureSpec.makeMeasureSpec(0, 0);
}
child.measure(childWidthSpec, childHeightSpec);
}
示例5: measureView
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
/**
* 測量View的尺寸<br/>
* 由於Android你中View需要測量後才能得到具體的尺寸數據<br/>
* 但是我們在使用中,通常都是初始化就需要得到尺寸數據<br/>
* 因此提供該工具方法,隻要對需要尺寸數據的View執行該方法<br/>
* 然後該View就可以取到尺寸信息。
*
* @param child
*/
public static void measureView(View child) {
ViewGroup.LayoutParams lp = child.getLayoutParams();
if (lp == null) {
lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
}
// View的寬度信息
int childMeasureWidth = ViewGroup.getChildMeasureSpec(0, 0, lp.width);
int childMeasureHeight;
if (lp.height > 0) {
// 最後一個參數表示:適合、匹配
childMeasureHeight = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY);
} else {
childMeasureHeight = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); // 未指定
}
//
child.measure(childMeasureWidth, childMeasureHeight);
}
示例6: getChildMeasureSpec
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
@Deprecated
public static int getChildMeasureSpec(int parentSize, int padding, int childDimension, boolean canScroll) {
int size = Math.max(0, parentSize - padding);
int resultSize = 0;
int resultMode = 0;
if (canScroll) {
if (childDimension >= 0) {
resultSize = childDimension;
resultMode = 1073741824;
} else {
resultSize = 0;
resultMode = 0;
}
} else if (childDimension >= 0) {
resultSize = childDimension;
resultMode = 1073741824;
} else if (childDimension == -1) {
resultSize = size;
resultMode = 1073741824;
} else if (childDimension == -2) {
resultSize = size;
resultMode = Integer.MIN_VALUE;
}
return MeasureSpec.makeMeasureSpec(resultSize, resultMode);
}
示例7: measureViewHeight
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
protected static int measureViewHeight(View view) {
ViewGroup.LayoutParams p = view.getLayoutParams();
if (p == null) {
p = new ViewGroup.LayoutParams(MATCH_PARENT,WRAP_CONTENT);
}
int childHeightSpec;
int childWidthSpec = ViewGroup.getChildMeasureSpec(0, 0, p.width);
if (p.height > 0) {
childHeightSpec = MeasureSpec.makeMeasureSpec(p.height, MeasureSpec.EXACTLY);
} else {
childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
}
view.measure(childWidthSpec, childHeightSpec);
return view.getMeasuredHeight();
}
示例8: initForMenu
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
@Override
public void initForMenu(Context context, MenuBuilder menu) {
super.initForMenu(context, menu);
final Resources res = context.getResources();
if (!mReserveOverflowSet) {
mReserveOverflow = reserveOverflow(mContext);
}
if (!mWidthLimitSet) {
mWidthLimit = res.getDisplayMetrics().widthPixels / 2;
}
// Measure for initial configuration
if (!mMaxItemsSet) {
mMaxItems = getResources_getInteger(context, R.integer.abs__max_action_buttons);
}
int width = mWidthLimit;
if (mReserveOverflow) {
if (mOverflowButton == null) {
mOverflowButton = new OverflowMenuButton(mSystemContext);
final int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
mOverflowButton.measure(spec, spec);
}
width -= mOverflowButton.getMeasuredWidth();
} else {
mOverflowButton = null;
}
mActionItemWidthLimit = width;
mMinCellSize = (int) (ActionMenuView.MIN_CELL_SIZE * res.getDisplayMetrics().density);
// Drop a scrap view as it may no longer reflect the proper context/config.
mScrapActionButtonView = null;
}
示例9: measureViewHeight
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
private static int measureViewHeight(View view) {
ViewGroup.LayoutParams p = view.getLayoutParams();
if (p == null) {
p = new ViewGroup.LayoutParams(MATCH_PARENT,WRAP_CONTENT);
}
int childHeightSpec;
int childWidthSpec = ViewGroup.getChildMeasureSpec(0, 0, p.width);
if (p.height > 0) {
childHeightSpec = MeasureSpec.makeMeasureSpec(p.height, MeasureSpec.EXACTLY);
} else {
childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
}
view.measure(childWidthSpec, childHeightSpec);
return view.getMeasuredHeight();
}
示例10: createView
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
public View createView() {
inflater = LayoutInflater.from(context);
content = inflater.inflate(contentResId, null);
realHeader = inflater.inflate(headerResId, null);
realHeaderLayoutParams = new FrameLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
realHeaderLayoutParams.gravity = Gravity.TOP;
// Use measured height here as an estimate of the header height, later
// on after the layout is complete
// we'll use the actual height
int widthMeasureSpec = MeasureSpec.makeMeasureSpec(
LayoutParams.MATCH_PARENT, MeasureSpec.EXACTLY);
int heightMeasureSpec = MeasureSpec.makeMeasureSpec(
LayoutParams.WRAP_CONTENT, MeasureSpec.EXACTLY);
realHeader.measure(widthMeasureSpec, heightMeasureSpec);
headerHeight = (int)(100 * realHeader.getResources().getDisplayMetrics().density + .5f);
listView = (ListView) content.findViewById(android.R.id.list);
if (listView != null) {
createListView();
} else {
createScrollView();
}
return root;
}
示例11: ensurePinnedHeaderLayout
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
private void ensurePinnedHeaderLayout(View header) {
if (header.isLayoutRequested()) {
int heightSpec;
int widthSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), this.mWidthMode);
LayoutParams layoutParams = header.getLayoutParams();
if (layoutParams == null || layoutParams.height <= 0) {
heightSpec = MeasureSpec.makeMeasureSpec(0, 0);
} else {
heightSpec = MeasureSpec.makeMeasureSpec(layoutParams.height, 1073741824);
}
header.measure(widthSpec, heightSpec);
header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight());
}
}
示例12: measureItem
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
private void measureItem(View child) {
int childWidthSpec;
ViewGroup.LayoutParams p = child.getLayoutParams();
if (p == null) {
p = new ViewGroup.LayoutParams(-2, -1);
}
int childHeightSpec = ViewGroup.getChildMeasureSpec(this.mHeightMeasureSpec, this.mListPadding.top + this.mListPadding.bottom, p.height);
int lpWidth = p.width;
if (lpWidth > 0) {
childWidthSpec = MeasureSpec.makeMeasureSpec(lpWidth, 1073741824);
} else {
childWidthSpec = MeasureSpec.makeMeasureSpec(0, 0);
}
child.measure(childWidthSpec, childHeightSpec);
}
示例13: updateSpecWithExtra
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
private int updateSpecWithExtra(int spec, int startInset, int endInset) {
if (startInset == 0 && endInset == 0) {
return spec;
}
int mode = MeasureSpec.getMode(spec);
if (mode == Integer.MIN_VALUE || mode == 1073741824) {
return MeasureSpec.makeMeasureSpec(Math.max(0, (MeasureSpec.getSize(spec) - startInset) - endInset), mode);
}
return spec;
}
示例14: onMeasure
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
boolean lockedExpanded;
boolean canCollapse;
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
if (widthMode == 1073741824) {
lockedExpanded = true;
} else {
lockedExpanded = false;
}
setFillViewport(lockedExpanded);
int childCount = this.mTabLayout.getChildCount();
if (childCount <= 1 || !(widthMode == 1073741824 || widthMode == Integer.MIN_VALUE)) {
this.mMaxTabWidth = -1;
} else {
if (childCount > 2) {
this.mMaxTabWidth = (int) (((float) MeasureSpec.getSize(widthMeasureSpec)) * 0.4f);
} else {
this.mMaxTabWidth = MeasureSpec.getSize(widthMeasureSpec) / 2;
}
this.mMaxTabWidth = Math.min(this.mMaxTabWidth, this.mStackedTabMaxWidth);
}
heightMeasureSpec = MeasureSpec.makeMeasureSpec(this.mContentHeight, 1073741824);
if (lockedExpanded || !this.mAllowCollapse) {
canCollapse = false;
} else {
canCollapse = true;
}
if (canCollapse) {
this.mTabLayout.measure(0, heightMeasureSpec);
if (this.mTabLayout.getMeasuredWidth() > MeasureSpec.getSize(widthMeasureSpec)) {
performCollapse();
} else {
performExpand();
}
} else {
performExpand();
}
int oldWidth = getMeasuredWidth();
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int newWidth = getMeasuredWidth();
if (lockedExpanded && oldWidth != newWidth) {
setTabSelected(this.mSelectedTabIndex);
}
}
示例15: onMeasure
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(536870911, Integer
.MIN_VALUE));
}