private int handleHeader(LayoutStateWrapper layoutState, LayoutChunkResult result, LayoutManagerHelper helper, boolean layoutInVertical, int parentWidth, int parentHeight, int parentHPadding, int parentVPadding) { if (mHeader == null) { return 0; } OrientationHelperEx orientationHelper = helper.getMainOrientationHelper(); final ViewGroup.MarginLayoutParams lp = new ViewGroup.MarginLayoutParams( mHeader.getLayoutParams()); // fill width int widthSpec = helper.getChildMeasureSpec(parentWidth - parentHPadding, layoutInVertical ? MATCH_PARENT : lp.width, !layoutInVertical); int heightSpec = helper.getChildMeasureSpec(parentHeight - parentVPadding, layoutInVertical ? lp.height : MeasureSpec.EXACTLY, layoutInVertical); helper.measureChildWithMargins(mHeader, widthSpec, heightSpec); return orientationHelper.getDecoratedMeasurement(mHeader); }
/** * Updates View bounds, possibly re-measuring and re-layouting it if the size changed. * * @param reactTag reactTag to lookup a View by * @param left left coordinate relative to parent * @param top top coordinate relative to parent * @param right right coordinate relative to parent * @param bottom bottom coordinate relative to parent */ /* package */ void updateViewBounds(int reactTag, int left, int top, int right, int bottom) { View view = resolveView(reactTag); int width = right - left; int height = bottom - top; if (view.getWidth() != width || view.getHeight() != height) { // size changed, we need to measure and layout the View view.measure( MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)); view.layout(left, top, right, bottom); } else { // same size, only location changed, there is a faster route. view.offsetLeftAndRight(left - view.getLeft()); view.offsetTopAndBottom(top - view.getTop()); } }
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); } }
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(); }
public void setupChild(List<TabModelInterface> list) { if (list != null && list.size() != 0) { this.mTabList.clear(); this.mTabList.addAll(list); this.tabStrip.removeAllViews(); for (TabModelInterface model : list) { TextView textView = new TextView(getContext()); textView.setGravity(17); textView.setText(model.getTabName()); textView.setTextColor(getResources().getColor(R.color.du)); textView.setTextSize(0, this.textSize); LayoutParams params = new LayoutParams(-2, -1); textView.setPadding(ViewUtils.dip2px(getContext(), 16.0f), 0, ViewUtils.dip2px (getContext(), 16.0f), 0); textView.setOnClickListener(new InternalTabClickListener()); this.tabStrip.addView(textView, params); textView.measure(MeasureSpec.makeMeasureSpec(0, 0), MeasureSpec.makeMeasureSpec (0, 0)); } initView(); } }
private int handleHeader(View header, LayoutStateWrapper layoutState, LayoutChunkResult result, LayoutManagerHelper helper, boolean layoutInVertical, int parentWidth, int parentHeight, int parentHPadding, int parentVPadding) { if (header == null) { return 0; } OrientationHelperEx orientationHelper = helper.getMainOrientationHelper(); final ViewGroup.MarginLayoutParams lp = new ViewGroup.MarginLayoutParams( header.getLayoutParams()); // fill width int widthSpec = helper.getChildMeasureSpec(parentWidth - parentHPadding, layoutInVertical ? MATCH_PARENT : lp.width, !layoutInVertical); int heightSpec = helper.getChildMeasureSpec(parentHeight - parentVPadding, layoutInVertical ? lp.height : MeasureSpec.EXACTLY, layoutInVertical); helper.measureChildWithMargins(header, widthSpec, heightSpec); return orientationHelper.getDecoratedMeasurement(header); }
private int handleFooter(View footer, LayoutStateWrapper layoutState, LayoutChunkResult result, LayoutManagerHelper helper, boolean layoutInVertical, int parentWidth, int parentHeight, int parentHPadding, int parentVPadding) { if (footer == null) { return 0; } OrientationHelperEx orientationHelper = helper.getMainOrientationHelper(); final ViewGroup.MarginLayoutParams lp = new ViewGroup.MarginLayoutParams( footer.getLayoutParams()); // fill width int widthSpec = helper.getChildMeasureSpec(parentWidth - parentHPadding, layoutInVertical ? MATCH_PARENT : lp.width, !layoutInVertical); int heightSpec = helper.getChildMeasureSpec(parentHeight - parentVPadding, layoutInVertical ? lp.height : MeasureSpec.EXACTLY, layoutInVertical); helper.measureChildWithMargins(footer, widthSpec, heightSpec); return orientationHelper.getDecoratedMeasurement(footer); }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); width = MeasureSpec.getSize(widthMeasureSpec); height = MeasureSpec.getSize(heightMeasureSpec); // Fit to screen. float scale; float scaleX = width / bmWidth; float scaleY = height / bmHeight; scale = Math.min(scaleX, scaleY); matrix.setScale(scale, scale); // minScale = scale; setImageMatrix(matrix); saveScale = 1f; // Center the image redundantYSpace = height - (scale * bmHeight); redundantXSpace = width - (scale * bmWidth); redundantYSpace /= (float) 2; redundantXSpace /= (float) 2; matrix.postTranslate(redundantXSpace, redundantYSpace); origWidth = width - 2 * redundantXSpace; origHeight = height - 2 * redundantYSpace; calcPadding(); setImageMatrix(matrix); }
private int getRealWidth(int mode, int size) { int ret = size; if (View.MeasureSpec.AT_MOST == mode) { int childrenWidth = 0; Params p = (Params) mParams; childrenWidth = mPaddingLeft + mPaddingRight; int count = 0; for (ViewBase child : mSubViews) { childrenWidth += child.getComMeasuredWidthWithMargin(); if (++count >= mColCount) { break; } else { childrenWidth += mItemHorizontalMargin; } } ret = Math.min(size, childrenWidth); } else if (View.MeasureSpec.EXACTLY == mode) { ret = size; } else { Log.e(TAG, "getRealWidth error mode:" + mode); } return ret; }
public static Bitmap loadBitmapFromView(View v) { if (v.getMeasuredHeight() > 0) { return null; } v.measure(MeasureSpec.makeMeasureSpec((int) DensityUtil.getScreenWidth(v.getContext()), 1073741824), MeasureSpec.makeMeasureSpec(0, 0)); Bitmap b = Bitmap.createBitmap(v.getMeasuredWidth(), v.getMeasuredHeight(), Config .ARGB_8888); Canvas c = new Canvas(b); v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight()); v.draw(c); return b; }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int width = MeasureSpec.getSize(widthMeasureSpec); int height = MeasureSpec.getSize(heightMeasureSpec); if (width >= 2 * mIllustration.getWidth() && width > height) { mPromoContent.setOrientation(LinearLayout.HORIZONTAL); setMaxChildWidth(mMaxChildWidthHorizontal); ApiCompatibilityUtils.setPaddingRelative( mIllustration, 0, 0, mIllustrationPaddingSide, 0); } else { mPromoContent.setOrientation(LinearLayout.VERTICAL); setMaxChildWidth(mMaxChildWidth); mIllustration.setPadding(0, 0, 0, mIllustrationPaddingBottom); } setMaxChildHeight(height - mFrameHeightMargin); super.onMeasure(widthMeasureSpec, heightMeasureSpec); }
private void measureContentView() { View rootView = mAnchorView.getRootView(); getBackground().getPadding(mCachedPaddingRect); // The maximum width of the bubble is determined by how wide the root view is. int maxContentWidth = rootView.getWidth() - mCachedPaddingRect.left - mCachedPaddingRect.right; // The maximum height of the bubble is determined by the available space below the anchor. int anchorYOverlap = (int) -(mYOverlapPercentage * mAnchorView.getHeight()); int maxContentHeight = getMaxAvailableHeight(mAnchorView, anchorYOverlap) - mCachedPaddingRect.top - mCachedPaddingRect.bottom; int contentWidthSpec = MeasureSpec.makeMeasureSpec(maxContentWidth, MeasureSpec.AT_MOST); int contentHeightSpec = MeasureSpec.makeMeasureSpec(maxContentHeight, MeasureSpec.AT_MOST); mContentView.measure(contentWidthSpec, contentHeightSpec); }
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()); } }
private void measureScrapChildWidth(View child, int position, int heightMeasureSpec) { int childWidthSpec; LayoutParams p = (LayoutParams) child.getLayoutParams(); if (p == null) { p = (LayoutParams) generateDefaultLayoutParams(); child.setLayoutParams(p); } p.viewType = this.mAdapter.getItemViewType(position); p.forceAdd = true; int childHeightSpec = ViewGroup.getChildMeasureSpec(heightMeasureSpec, 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); }
@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); }
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); int widthMode = MeasureSpec.getMode(widthMeasureSpec); int heightMode = MeasureSpec.getMode(heightMeasureSpec); int sizeWidth = MeasureSpec.getSize(widthMeasureSpec); int sizeHeight = MeasureSpec.getSize(heightMeasureSpec); this.totalWidth = (sizeWidth - getPaddingLeft()) - getPaddingRight(); if (this.listData != null && this.listData.size() > 0) { if (this.listData.size() != 1) { this.singleWidth = (this.totalWidth - (this.gap * 2)) / 3; this.singleHeight = this.singleWidth; } else if (this.isSmallScreen) { this.singleWidth = this.defaultWidth; this.singleHeight = this.defaultHeight; } else { this.singleWidth = ((Photo) this.listData.get(0)).preview_width; this.singleHeight = ((Photo) this.listData.get(0)).preview_height; } measureChildren(MeasureSpec.makeMeasureSpec(this.singleWidth, 1073741824), MeasureSpec.makeMeasureSpec(this.singleHeight, 1073741824)); int measureWidth = (this.singleWidth * this.columns) + (this.gap * (this.columns - 1)); setMeasuredDimension(sizeWidth, (this.singleHeight * this.rows) + (this.gap * (this .rows - 1))); } }
private static boolean isMeasurementUpToDate(int childSize, int spec, int dimension) { int specMode = MeasureSpec.getMode(spec); int specSize = MeasureSpec.getSize(spec); if (dimension > 0 && childSize != dimension) { return false; } switch (specMode) { case Integer.MIN_VALUE: if (specSize < childSize) { return false; } return true; case 0: return true; case 1073741824: if (specSize != childSize) { return false; } return true; default: return false; } }
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); }
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (MeasureSpec.getMode(widthMeasureSpec) != 1073741824) { throw new IllegalStateException("Must measure with an exact width"); } int height; int heightPadding = getPaddingTop() + getPaddingBottom(); int childHeightSpec = getChildMeasureSpec(heightMeasureSpec, heightPadding, -2); int widthSize = MeasureSpec.getSize(widthMeasureSpec); int childWidthSpec = getChildMeasureSpec(widthMeasureSpec, (int) (((float) widthSize) * 0.2f), -2); this.mPrevText.measure(childWidthSpec, childHeightSpec); this.mCurrText.measure(childWidthSpec, childHeightSpec); this.mNextText.measure(childWidthSpec, childHeightSpec); if (MeasureSpec.getMode(heightMeasureSpec) == 1073741824) { height = MeasureSpec.getSize(heightMeasureSpec); } else { height = Math.max(getMinHeight(), this.mCurrText.getMeasuredHeight() + heightPadding); } setMeasuredDimension(widthSize, ViewCompat.resolveSizeAndState(height, heightMeasureSpec, ViewCompat.getMeasuredState(this.mCurrText) << 16)); }
/** * Assert onMeasure() with given parameters will result in expected measured size. */ @SuppressLint("WrongCall") private static void assertMeasuredSize(SurfaceViewRenderer surfaceViewRenderer, RendererCommon.ScalingType scalingType, String frameDimensions, int expectedWidth, int expectedHeight, int widthSpec, int heightSpec) { surfaceViewRenderer.setScalingType(scalingType); surfaceViewRenderer.onMeasure(widthSpec, heightSpec); final int measuredWidth = surfaceViewRenderer.getMeasuredWidth(); final int measuredHeight = surfaceViewRenderer.getMeasuredHeight(); if (measuredWidth != expectedWidth || measuredHeight != expectedHeight) { fail("onMeasure(" + MeasureSpec.toString(widthSpec) + ", " + MeasureSpec.toString(heightSpec) + ")" + " with scaling type " + scalingType + " and frame: " + frameDimensions + " expected measured size " + expectedWidth + "x" + expectedHeight + ", but was " + measuredWidth + "x" + measuredHeight); } }
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if (this.mTarget == null) { ensureTarget(); } if (this.mTarget != null) { this.mTarget.measure(MeasureSpec.makeMeasureSpec((getMeasuredWidth() - getPaddingLeft()) - getPaddingRight(), 1073741824), MeasureSpec.makeMeasureSpec((getMeasuredHeight() - getPaddingTop()) - getPaddingBottom(), 1073741824)); this.mCircleView.measure(MeasureSpec.makeMeasureSpec(this.mCircleWidth, 1073741824), MeasureSpec.makeMeasureSpec(this.mCircleHeight, 1073741824)); if (!(this.mUsingCustomStart || this.mOriginalOffsetCalculated)) { this.mOriginalOffsetCalculated = true; int i = -this.mCircleView.getMeasuredHeight(); this.mOriginalOffsetTop = i; this.mCurrentTargetOffsetTop = i; } this.mCircleViewIndex = -1; for (int index = 0; index < getChildCount(); index++) { if (getChildAt(index) == this.mCircleView) { this.mCircleViewIndex = index; return; } } } }
public static void measureView(View view) { ViewGroup.LayoutParams p = view.getLayoutParams(); if (p == null) { p = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); } int childWidthSpec = ViewGroup.getChildMeasureSpec(0, 0 + 0, p.width); int lpHeight = p.height; int childHeightSpec; if (lpHeight > 0) { childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight, MeasureSpec.EXACTLY); } else { childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); } view.measure(childWidthSpec, childHeightSpec); }
public int measureContentWidth() { int oldMaxActivityCount = this.mMaxActivityCount; this.mMaxActivityCount = MAX_ACTIVITY_COUNT_UNLIMITED; int contentWidth = 0; View itemView = null; int widthMeasureSpec = MeasureSpec.makeMeasureSpec(0, 0); int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, 0); int count = getCount(); for (int i = 0; i < count; i++) { itemView = getView(i, itemView, null); itemView.measure(widthMeasureSpec, heightMeasureSpec); contentWidth = Math.max(contentWidth, itemView.getMeasuredWidth()); } this.mMaxActivityCount = oldMaxActivityCount; return contentWidth; }
@Test public void measure_honors_measure_specs() { final PhialButton button = new PhialButton(context); button.setSuggestedSize(10); button.setShadowSize(2); button.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); assertEquals(12, button.getMeasuredWidth()); assertEquals(12, button.getMeasuredHeight()); final int specs = makeMeasureSpec(15, MeasureSpec.AT_MOST); button.measure(specs, specs); assertEquals(12, button.getMeasuredWidth()); assertEquals(12, button.getMeasuredHeight()); final int specsReduced = makeMeasureSpec(10, MeasureSpec.AT_MOST); button.measure(specsReduced, specsReduced); assertEquals(10, button.getMeasuredWidth()); assertEquals(10, button.getMeasuredHeight()); final int specsExactly = makeMeasureSpec(15, MeasureSpec.EXACTLY); button.measure(specsExactly, specsExactly); assertEquals(15, button.getMeasuredWidth()); assertEquals(15, button.getMeasuredHeight()); }
@NonNull @Override protected final Bitmap doInBackground(@NonNull final Tab key, @NonNull final TabItem... params) { TabItem tabItem = params[0]; PhoneTabViewHolder viewHolder = (PhoneTabViewHolder) tabItem.getViewHolder(); View content = viewHolder.content; viewHolder.content = null; int width = parent.getWidth(); int height = parent.getHeight(); content.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)); content.layout(0, 0, content.getMeasuredWidth(), content.getMeasuredHeight()); Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); content.draw(canvas); return bitmap; }
/** * 测量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); }
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int height; int widthMode = MeasureSpec.getMode(widthMeasureSpec); int heightMode = MeasureSpec.getMode(heightMeasureSpec); int widthSize = MeasureSpec.getSize(widthMeasureSpec); int heightSize = MeasureSpec.getSize(heightMeasureSpec); buildViewForMeasuring(); int width = calculateLayoutWidth(widthSize, widthMode); if (heightMode == 1073741824) { height = heightSize; } else { height = getDesiredHeight(this.itemsLayout); if (heightMode == Integer.MIN_VALUE) { height = Math.min(height, heightSize); } } setMeasuredDimension(width, height); }
private int measureShort(int measureSpec) { int specMode = MeasureSpec.getMode(measureSpec); int specSize = MeasureSpec.getSize(measureSpec); if (specMode == 1073741824) { return specSize; } int result = (int) ((((2.0f * this.mRadius) + ((float) getPaddingTop())) + ((float) getPaddingBottom())) + 1.0f); if (specMode == Integer.MIN_VALUE) { return Math.min(result, specSize); } return result; }
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if (MeasureSpec.getMode(widthMeasureSpec) == 1073741824 && TabLayout.this.mMode == 1 && TabLayout.this.mTabGravity == 1) { int i; int count = getChildCount(); int largestTabWidth = 0; int z = count; for (i = 0; i < z; i++) { View child = getChildAt(i); if (child.getVisibility() == 0) { largestTabWidth = Math.max(largestTabWidth, child.getMeasuredWidth()); } } if (largestTabWidth > 0) { boolean remeasure = false; if (largestTabWidth * count <= getMeasuredWidth() - (TabLayout.this.dpToPx(16) * 2)) { for (i = 0; i < count; i++) { LayoutParams lp = (LayoutParams) getChildAt(i).getLayoutParams(); if (lp.width != largestTabWidth || lp.weight != 0.0f) { lp.width = largestTabWidth; lp.weight = 0.0f; remeasure = true; } } } else { TabLayout.this.mTabGravity = 0; TabLayout.this.updateTabViews(false); remeasure = true; } if (remeasure) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } }
@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; }
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; } }
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()); } }
private int measureHeight(int heightMeasure) { int measureMode = MeasureSpec.getMode(heightMeasure); int measureSize = MeasureSpec.getSize(heightMeasure); int result = (int) (this.bottomPadding + (this.longLineHeight * 2.0f)); switch (measureMode) { case Integer.MIN_VALUE: result = Math.min(result, measureSize); break; case 1073741824: result = Math.max(result, measureSize); break; } this.height = result; return result; }
private int measureNumColumns(ViewGroup layout, CharSequence item, CharSequence title) { int colWidth = 0; int viewWidth = 0; if (getSize() > 0) { // Use the first item to measure the column width TextView tempView = createTextView(item); tempView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); tempView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); colWidth = tempView.getMeasuredWidth() + 4; // Stack overflow when called just after resized layout !? viewWidth = layout.getWidth(); // If table layout not inflated yet, use device width if (viewWidth <= 0) { viewWidth = mRes.getDisplayMetrics().widthPixels - 2 * mRes.getDimensionPixelOffset(R.dimen.activity_horizontal_margin); } if (title != null) { tempView = createTextView(title); tempView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); tempView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); viewWidth -= tempView.getMeasuredWidth(); } } if (colWidth != 0) { return Math.max(1, viewWidth/colWidth); } else { return 1; } }
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (isIconified()) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); return; } int widthMode = MeasureSpec.getMode(widthMeasureSpec); int width = MeasureSpec.getSize(widthMeasureSpec); switch (widthMode) { case Integer.MIN_VALUE: if (this.mMaxWidth <= 0) { width = Math.min(getPreferredWidth(), width); break; } else { width = Math.min(this.mMaxWidth, width); break; } case 0: width = this.mMaxWidth > 0 ? this.mMaxWidth : getPreferredWidth(); break; case 1073741824: if (this.mMaxWidth > 0) { width = Math.min(this.mMaxWidth, width); break; } break; } super.onMeasure(MeasureSpec.makeMeasureSpec(width, 1073741824), heightMeasureSpec); }
@SuppressLint("RtlHardcoded") private void show() { Log.v(TAG, "show()"); if (mView == null) { mView = inflateView(mRootView); mView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { return true; } }); FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mView.getLayoutParams(); params.leftMargin = getMargin(); params.rightMargin = getMargin(); params.gravity = getOpenPosition().x < getScreenWidth() / 2 ? Gravity.LEFT : Gravity.RIGHT; mRootView.addView(mView); mView.measure(MeasureSpec.makeMeasureSpec(mRootView.getWidth() - getMargin(), MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(mRootView.getHeight() - getMargin() - getOpenPosition().y, MeasureSpec.AT_MOST)); } else { mView.setVisibility(View.VISIBLE); } // Adjust view location if (!mIsDestroyed) { if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { mView.setTranslationX(-mDraggableIcon.getWidth()); mView.setTranslationY(getOpenPosition().y); } else { mView.setTranslationY(getOpenPosition().y + mDraggableIcon.getHeight()); } } // Animate calc in mView.setAlpha(0); mView.animate().setDuration(150).alpha(1).setListener(null); onShow(); }
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { this.size.set(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.getSize (heightMeasureSpec)); if (this.mMaxWidth >= 0 || this.mMaxHeight >= 0) { this.maxSize.set(this.mMaxWidth, this.mMaxHeight); constrainTo(this.size, this.maxSize); widthMeasureSpec = MeasureSpec.makeMeasureSpec(this.size.x, 1073741824); heightMeasureSpec = MeasureSpec.makeMeasureSpec(this.size.y, 1073741824); } super.onMeasure(widthMeasureSpec, heightMeasureSpec); onMeasurePage(widthMeasureSpec, heightMeasureSpec); }