本文整理匯總了Java中android.view.View.MeasureSpec.getMode方法的典型用法代碼示例。如果您正苦於以下問題:Java MeasureSpec.getMode方法的具體用法?Java MeasureSpec.getMode怎麽用?Java MeasureSpec.getMode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.view.View.MeasureSpec
的用法示例。
在下文中一共展示了MeasureSpec.getMode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onMeasure
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
boolean lockedExpanded = widthMode == 1073741824;
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;
}
int oldWidth = getMeasuredWidth();
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int newWidth = getMeasuredWidth();
if (lockedExpanded && oldWidth != newWidth) {
setCurrentItem(this.mSelectedTabIndex);
}
}
示例2: onMeasure
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
float height;
int measuredWidth = MeasureSpec.getSize(widthMeasureSpec);
if (MeasureSpec.getMode(heightMeasureSpec) == 1073741824) {
height = (float) MeasureSpec.getSize(heightMeasureSpec);
} else {
this.mBounds.setEmpty();
this.mBounds.bottom = (int) (this.mPaintText.descent() - this.mPaintText.ascent());
height = ((((float) (this.mBounds.bottom - this.mBounds.top)) + this
.mFooterLineHeight) + this.mFooterPadding) + this.mTopPadding;
if (this.mFooterIndicatorStyle != IndicatorStyle.None) {
height += this.mFooterIndicatorHeight;
}
}
setMeasuredDimension(measuredWidth, (int) height);
}
示例3: onMeasure
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
/**
*
*/
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int height = MeasureSpec.getSize(heightMeasureSpec);
int width = MeasureSpec.getSize(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
final View child = getChildAt(0);
if (child == null) {
setMeasuredDimension(0, width);
return;
}
if (child.isLayoutRequested()) {
// Always let child be as tall as it wants.
measureChild(child, widthMeasureSpec,
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
}
if (heightMode == MeasureSpec.UNSPECIFIED) {
ViewGroup.LayoutParams lp = getLayoutParams();
if (lp.height > 0) {
height = lp.height;
} else {
height = child.getMeasuredHeight();
}
}
setMeasuredDimension(width, height);
}
示例4: onMeasure
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (this.mFillViewport && MeasureSpec.getMode(heightMeasureSpec) != 0 && getChildCount() > 0) {
View child = getChildAt(0);
int height = getMeasuredHeight();
if (child.getMeasuredHeight() < height) {
child.measure(getChildMeasureSpec(widthMeasureSpec, getPaddingLeft() + getPaddingRight(), ((FrameLayout.LayoutParams) child.getLayoutParams()).width), MeasureSpec.makeMeasureSpec((height - getPaddingTop()) - getPaddingBottom(), 1073741824));
}
}
}
示例5: getDefaultSize2
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
private static int getDefaultSize2(int size, int measureSpec) {
int result = size;
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);
switch (specMode) {
case Integer.MIN_VALUE:
return Math.min(size, specSize);
case 0:
return size;
case 1073741824:
return specSize;
default:
return result;
}
}
示例6: 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;
}
示例7: resolveAdjustedSize
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
public int resolveAdjustedSize(int desiredSize, int measureSpec) {
int result = desiredSize;
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);
switch (specMode) {
case Integer.MIN_VALUE:
return Math.min(desiredSize, specSize);
case 0:
return desiredSize;
case 1073741824:
return specSize;
default:
return result;
}
}
示例8: onMeasure
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
boolean z;
boolean wasFormatted = this.mFormatItems;
if (MeasureSpec.getMode(widthMeasureSpec) == 1073741824) {
z = true;
} else {
z = false;
}
this.mFormatItems = z;
if (wasFormatted != this.mFormatItems) {
this.mFormatItemsWidth = 0;
}
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
if (!(!this.mFormatItems || this.mMenu == null || widthSize == this.mFormatItemsWidth)) {
this.mFormatItemsWidth = widthSize;
this.mMenu.onItemsChanged(true);
}
int childCount = getChildCount();
if (!this.mFormatItems || childCount <= 0) {
for (int i = 0; i < childCount; i++) {
LayoutParams lp = (LayoutParams) getChildAt(i).getLayoutParams();
lp.rightMargin = 0;
lp.leftMargin = 0;
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
return;
}
onMeasureExactFormat(widthMeasureSpec, heightMeasureSpec);
}
示例9: createPinnedShadow
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
private void createPinnedShadow(int position) {
int heightMode;
int heightSize;
PinnedViewShadow pinnedShadow = this.mRecycleShadow;
View recycleView = pinnedShadow == null ? null : pinnedShadow.view;
this.mRecycleShadow = null;
View pinnedView = getAdapter().getView(position, recycleView, this);
LayoutParams layoutParams = (LayoutParams) pinnedView.getLayoutParams();
if (layoutParams == null) {
heightMode = Integer.MIN_VALUE;
heightSize = getHeight();
} else {
heightMode = MeasureSpec.getMode(layoutParams.height);
heightSize = MeasureSpec.getSize(layoutParams.height);
}
if (heightMode == 0) {
heightMode = 1073741824;
}
int maxHeight = (getHeight() - getListPaddingTop()) - getListPaddingBottom();
if (heightSize > maxHeight) {
heightSize = maxHeight;
}
pinnedView.measure(MeasureSpec.makeMeasureSpec((getWidth() - getListPaddingLeft()) -
getListPaddingRight(), 1073741824), MeasureSpec.makeMeasureSpec(heightSize,
heightMode));
pinnedView.layout(0, 0, pinnedView.getMeasuredWidth(), pinnedView.getMeasuredHeight());
this.mTranslateY = 0;
if (pinnedShadow == null) {
pinnedShadow = new PinnedViewShadow();
}
pinnedShadow.position = position;
pinnedShadow.view = pinnedView;
this.mPinnedShadow = pinnedShadow;
}
示例10: measureWidth
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
private int measureWidth(int widthMeasureSpec) {
int measureMode = MeasureSpec.getMode(widthMeasureSpec);
int measureSize = MeasureSpec.getSize(widthMeasureSpec);
int result = getSuggestedMinimumWidth();
switch (measureMode) {
case Integer.MIN_VALUE:
case 1073741824:
result = measureSize;
break;
}
this.width = result;
return result;
}
示例11: onMeasure
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
prepareChildren();
ensurePreDrawListener();
int paddingLeft = getPaddingLeft();
int paddingTop = getPaddingTop();
int paddingRight = getPaddingRight();
int paddingBottom = getPaddingBottom();
int layoutDirection = ViewCompat.getLayoutDirection(this);
boolean isRtl = layoutDirection == 1;
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
int widthPadding = paddingLeft + paddingRight;
int heightPadding = paddingTop + paddingBottom;
int widthUsed = getSuggestedMinimumWidth();
int heightUsed = getSuggestedMinimumHeight();
int childState = 0;
boolean applyInsets = this.mLastInsets != null && ViewCompat.getFitsSystemWindows(this);
int childCount = this.mDependencySortedChildren.size();
for (int i = 0; i < childCount; i++) {
View child = (View) this.mDependencySortedChildren.get(i);
LayoutParams lp = (LayoutParams) child.getLayoutParams();
int keylineWidthUsed = 0;
if (lp.keyline >= 0 && widthMode != 0) {
int keylinePos = getKeyline(lp.keyline);
int keylineGravity = GravityCompat.getAbsoluteGravity(resolveKeylineGravity(lp.gravity), layoutDirection) & 7;
if ((keylineGravity == 3 && !isRtl) || (keylineGravity == 5 && isRtl)) {
keylineWidthUsed = Math.max(0, (widthSize - paddingRight) - keylinePos);
} else if ((keylineGravity == 5 && !isRtl) || (keylineGravity == 3 && isRtl)) {
keylineWidthUsed = Math.max(0, keylinePos - paddingLeft);
}
}
int childWidthMeasureSpec = widthMeasureSpec;
int childHeightMeasureSpec = heightMeasureSpec;
if (applyInsets && !ViewCompat.getFitsSystemWindows(child)) {
int vertInsets = this.mLastInsets.getSystemWindowInsetTop() + this.mLastInsets.getSystemWindowInsetBottom();
childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(widthSize - (this.mLastInsets.getSystemWindowInsetLeft() + this.mLastInsets.getSystemWindowInsetRight()), widthMode);
childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize - vertInsets, heightMode);
}
Behavior b = lp.getBehavior();
if (b == null || !b.onMeasureChild(this, child, childWidthMeasureSpec, keylineWidthUsed, childHeightMeasureSpec, 0)) {
onMeasureChild(child, childWidthMeasureSpec, keylineWidthUsed, childHeightMeasureSpec, 0);
}
widthUsed = Math.max(widthUsed, ((child.getMeasuredWidth() + widthPadding) + lp.leftMargin) + lp.rightMargin);
heightUsed = Math.max(heightUsed, ((child.getMeasuredHeight() + heightPadding) + lp.topMargin) + lp.bottomMargin);
childState = ViewCompat.combineMeasuredStates(childState, ViewCompat.getMeasuredState(child));
}
setMeasuredDimension(ViewCompat.resolveSizeAndState(widthUsed, widthMeasureSpec, -16777216 & childState), ViewCompat.resolveSizeAndState(heightUsed, heightMeasureSpec, childState << 16));
}
示例12: onMeasure
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (MeasureSpec.getMode(widthMeasureSpec) != 1073741824) {
throw new IllegalStateException(getClass().getSimpleName() + " can only be used " + "with android:layout_width=\"match_parent\" (or fill_parent)");
} else if (MeasureSpec.getMode(heightMeasureSpec) == 0) {
throw new IllegalStateException(getClass().getSimpleName() + " can only be used " + "with android:layout_height=\"wrap_content\"");
} else {
int contentWidth = MeasureSpec.getSize(widthMeasureSpec);
int maxHeight = this.mContentHeight > 0 ? this.mContentHeight : MeasureSpec.getSize(heightMeasureSpec);
int verticalPadding = getPaddingTop() + getPaddingBottom();
int availableWidth = (contentWidth - getPaddingLeft()) - getPaddingRight();
int height = maxHeight - verticalPadding;
int childSpecHeight = MeasureSpec.makeMeasureSpec(height, Integer.MIN_VALUE);
if (this.mClose != null) {
MarginLayoutParams lp = (MarginLayoutParams) this.mClose.getLayoutParams();
availableWidth = measureChildView(this.mClose, availableWidth, childSpecHeight, 0) - (lp.leftMargin + lp.rightMargin);
}
if (this.mMenuView != null && this.mMenuView.getParent() == this) {
availableWidth = measureChildView(this.mMenuView, availableWidth, childSpecHeight, 0);
}
if (this.mTitleLayout != null && this.mCustomView == null) {
if (this.mTitleOptional) {
this.mTitleLayout.measure(MeasureSpec.makeMeasureSpec(0, 0), childSpecHeight);
int titleWidth = this.mTitleLayout.getMeasuredWidth();
boolean titleFits = titleWidth <= availableWidth;
if (titleFits) {
availableWidth -= titleWidth;
}
this.mTitleLayout.setVisibility(titleFits ? 0 : 8);
} else {
availableWidth = measureChildView(this.mTitleLayout, availableWidth, childSpecHeight, 0);
}
}
if (this.mCustomView != null) {
int customWidth;
int customHeight;
LayoutParams lp2 = this.mCustomView.getLayoutParams();
int customWidthMode = lp2.width != -2 ? 1073741824 : Integer.MIN_VALUE;
if (lp2.width >= 0) {
customWidth = Math.min(lp2.width, availableWidth);
} else {
customWidth = availableWidth;
}
int customHeightMode = lp2.height != -2 ? 1073741824 : Integer.MIN_VALUE;
if (lp2.height >= 0) {
customHeight = Math.min(lp2.height, height);
} else {
customHeight = height;
}
this.mCustomView.measure(MeasureSpec.makeMeasureSpec(customWidth, customWidthMode), MeasureSpec.makeMeasureSpec(customHeight, customHeightMode));
}
if (this.mContentHeight <= 0) {
int measuredHeight = 0;
int count = getChildCount();
for (int i = 0; i < count; i++) {
int paddedViewHeight = getChildAt(i).getMeasuredHeight() + verticalPadding;
if (paddedViewHeight > measuredHeight) {
measuredHeight = paddedViewHeight;
}
}
setMeasuredDimension(contentWidth, measuredHeight);
return;
}
setMeasuredDimension(contentWidth, maxHeight);
}
}
示例13: onMeasure
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
@TargetApi(11)
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int i;
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
int childWidth = 0;
int childHeight = 0;
int childState = 0;
if (this.mAdapter == null) {
i = 0;
} else {
i = this.mAdapter.getCount();
}
this.mItemCount = i;
if (this.mItemCount > 0 && (widthMode == 0 || heightMode == 0)) {
View child = obtainView(0, this.mIsScrap);
measureScrapChildWidth(child, 0, heightMeasureSpec);
childWidth = child.getMeasuredWidth();
childHeight = child.getMeasuredHeight();
if (VERSION.SDK_INT >= 11) {
childState = combineMeasuredStates(0, child.getMeasuredState());
}
if (recycleOnMeasure() && this.mRecycler.shouldRecycleViewType(((LayoutParams) child.getLayoutParams()).viewType)) {
this.mRecycler.addScrapView(child, -1);
}
}
if (heightMode == 0) {
heightSize = ((this.mListPadding.top + this.mListPadding.bottom) + childHeight) + getHorizontalScrollbarHeight();
} else if (heightMode == Integer.MIN_VALUE && this.mItemCount > 0 && this.mMeasureWithChild > -1) {
heightSize = measureWithLargeChildren(heightMeasureSpec, this.mMeasureWithChild, this.mMeasureWithChild, widthSize, heightSize, -1)[1];
} else if (VERSION.SDK_INT >= 11) {
heightSize |= -16777216 & childState;
}
if (widthMode == 0) {
widthSize = ((this.mListPadding.left + this.mListPadding.right) + childWidth) + (getHorizontalFadingEdgeLength() * 2);
}
if (widthMode == Integer.MIN_VALUE) {
widthSize = measureWidthOfChildren(heightMeasureSpec, 0, -1, widthSize, -1);
}
setMeasuredDimension(widthSize, heightSize);
this.mHeightMeasureSpec = heightMeasureSpec;
}
示例14: getHeightMode
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
public int getHeightMode() {
return MeasureSpec.getMode(this.mHeightSpec);
}
示例15: onMeasure
import android.view.View.MeasureSpec; //導入方法依賴的package包/類
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (this.mPopup != null && MeasureSpec.getMode(widthMeasureSpec) == Integer.MIN_VALUE) {
setMeasuredDimension(Math.min(Math.max(getMeasuredWidth(), compatMeasureContentWidth(getAdapter(), getBackground())), MeasureSpec.getSize(widthMeasureSpec)), getMeasuredHeight());
}
}