List of usage examples for android.view View getMeasuredWidth
public final int getMeasuredWidth()
From source file:bw.com.yunifangstore.view.LazyViewPager.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mInLayout = true;// w w w . j a va 2 s. c o m populate(); mInLayout = false; final int count = getChildCount(); final int width = r - l; for (int i = 0; i < count; i++) { View child = getChildAt(i); ItemInfo ii; if (child.getVisibility() != GONE && (ii = infoForChild(child)) != null) { int loff = (width + mPageMargin) * ii.position; int childLeft = getPaddingLeft() + loff; int childTop = getPaddingTop(); if (DEBUG) Log.v(TAG, "Positioning #" + i + " " + child + " f=" + ii.object + ":" + childLeft + "," + childTop + " " + child.getMeasuredWidth() + "x" + child.getMeasuredHeight()); child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(), childTop + child.getMeasuredHeight()); } } mFirstLayout = false; }
From source file:org.thoughtland.xlocation.ActivityShare.java
private void blueStreakOfProgress(Integer current, Integer max) { // Set up the progress bar if (mProgressWidth == 0) { final View vShareProgressEmpty = (View) findViewById(R.id.vShareProgressEmpty); mProgressWidth = vShareProgressEmpty.getMeasuredWidth(); }// w w w . j a va2 s . c om // Display stuff if (max == 0) max = 1; int width = (int) ((float) mProgressWidth) * current / max; View vShareProgressFull = (View) findViewById(R.id.vShareProgressFull); vShareProgressFull.getLayoutParams().width = width; vShareProgressFull.invalidate(); vShareProgressFull.requestLayout(); }
From source file:com.cnpeng.cnpeng_mydemosfrom2016_12.a_12_GetLocalFiles_VP_FM.CustomNoPreLoadViewPager.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mInLayout = true;/*from w w w . j av a2 s . c o m*/ populate(); mInLayout = false; final int count = getChildCount(); final int width = r - l; for (int i = 0; i < count; i++) { View child = getChildAt(i); ItemInfo ii; if (child.getVisibility() != GONE && (ii = infoForChild(child)) != null) { int loff = (width + mPageMargin) * ii.position; int childLeft = getPaddingLeft() + loff; int childTop = getPaddingTop(); if (DEBUG) { Log.v(TAG, "Positioning #" + i + " " + child + " f=" + ii.object + ":" + childLeft + "," + childTop + " " + child.getMeasuredWidth() + "x" + child.getMeasuredHeight()); } child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(), childTop + child.getMeasuredHeight()); } } mFirstLayout = false; }
From source file:ca.co.rufus.androidboilerplate.ui.DebugDrawerLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mInLayout = true;/*from www . j av a2 s. c o m*/ final int width = r - l; final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (child.getVisibility() == GONE) { continue; } final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (isContentView(child)) { child.layout(lp.leftMargin, lp.topMargin, lp.leftMargin + child.getMeasuredWidth(), lp.topMargin + child.getMeasuredHeight()); } else { // Drawer, if it wasn't onMeasure would have thrown an exception. final int childWidth = child.getMeasuredWidth(); final int childHeight = child.getMeasuredHeight(); int childLeft; final float newOffset; if (checkDrawerViewAbsoluteGravity(child, Gravity.LEFT)) { childLeft = -childWidth + (int) (childWidth * lp.onScreen); newOffset = (float) (childWidth + childLeft) / childWidth; } else { // Right; onMeasure checked for us. childLeft = width - (int) (childWidth * lp.onScreen); newOffset = (float) (width - childLeft) / childWidth; } final boolean changeOffset = newOffset != lp.onScreen; final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (vgrav) { default: case Gravity.TOP: { child.layout(childLeft, lp.topMargin, childLeft + childWidth, lp.topMargin + childHeight); break; } case Gravity.BOTTOM: { final int height = b - t; child.layout(childLeft, height - lp.bottomMargin - child.getMeasuredHeight(), childLeft + childWidth, height - lp.bottomMargin); break; } case Gravity.CENTER_VERTICAL: { final int height = b - t; int childTop = (height - childHeight) / 2; // Offset for margins. If things don't fit right because of // bad measurement before, oh well. if (childTop < lp.topMargin) { childTop = lp.topMargin; } else if (childTop + childHeight > height - lp.bottomMargin) { childTop = height - lp.bottomMargin - childHeight; } child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight); break; } } if (changeOffset) { setDrawerViewOffset(child, newOffset); } final int newVisibility = lp.onScreen > 0 ? VISIBLE : INVISIBLE; if (child.getVisibility() != newVisibility) { child.setVisibility(newVisibility); } } } mInLayout = false; mFirstLayout = false; }
From source file:android.support.v7.widget.LinearLayoutCompat.java
private void forceUniformHeight(int count, int widthMeasureSpec) { // Pretend that the linear layout has an exact size. This is the measured height of // ourselves. The measured height should be the max height of the children, changed // to accommodate the heightMeasureSpec from the parent int uniformMeasureSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY); for (int i = 0; i < count; ++i) { final View child = getVirtualChildAt(i); if (child.getVisibility() != GONE) { LinearLayoutCompat.LayoutParams lp = (LinearLayoutCompat.LayoutParams) child.getLayoutParams(); if (lp.height == LayoutParams.MATCH_PARENT) { // Temporarily force children to reuse their old measured width // FIXME: this may not be right for something like wrapping text? int oldWidth = lp.width; lp.width = child.getMeasuredWidth(); // Remeasure with new dimensions measureChildWithMargins(child, widthMeasureSpec, 0, uniformMeasureSpec, 0); lp.width = oldWidth;/*from www .java 2s . c o m*/ } } } }
From source file:com.base.view.slidemenu.SlideMenu.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { final int count = getChildCount(); final int slideMode = mSlideMode; final int statusBarHeight = STATUS_BAR_HEIGHT; final int measureHeight = MeasureSpec.getSize(heightMeasureSpec); final int measureHeightMode = MeasureSpec.getMode(heightMeasureSpec); boolean needRemeasure = false; int maxChildWidth = 0, maxChildHeight = 0; for (int index = 0; index < count; index++) { View child = getChildAt(index); LayoutParams layoutParams = (LayoutParams) child.getLayoutParams(); needRemeasure |= (MeasureSpec.EXACTLY != measureHeightMode && LayoutParams.MATCH_PARENT == layoutParams.height); switch (layoutParams.role) { case LayoutParams.ROLE_CONTENT: measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0); break; case LayoutParams.ROLE_PRIMARY_MENU: case LayoutParams.ROLE_SECONDARY_MENU: measureChildWithMargins(child, widthMeasureSpec, 0, slideMode == MODE_SLIDE_WINDOW ? MeasureSpec.makeMeasureSpec(measureHeight - statusBarHeight, MeasureSpec.getMode(heightMeasureSpec)) : heightMeasureSpec, 0);//ww w .j a v a 2s. c o m break; } maxChildWidth = Math.max(maxChildWidth, child.getMeasuredWidth()); maxChildHeight = Math.max(maxChildHeight, child.getMeasuredHeight()); } maxChildWidth += getPaddingLeft() + getPaddingRight(); maxChildHeight += getPaddingTop() + getPaddingBottom(); setMeasuredDimension(resolveSize(maxChildWidth, widthMeasureSpec), resolveSize(maxChildHeight, heightMeasureSpec)); // we know the exactly size of SlideMenu, so we should use the new size // to remeasure the child if (needRemeasure) { for (int index = 0; index < count; index++) { View child = getChildAt(index); if (View.GONE != child.getVisibility() && LayoutParams.MATCH_PARENT == child.getLayoutParams().height) { measureChildWithMargins(child, widthMeasureSpec, 0, MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY), 0); } } } }
From source file:com.doubleTwist.drawerlib.ADrawerLayout.java
protected void layoutView(View v, int l, int t, int r, int b) { LayoutParams params = (LayoutParams) v.getLayoutParams(); Rect bounds = new Rect(); Rect boundsWithoutPeek = new Rect(); int gravity = params.gravity; switch (gravity) { case Gravity.RIGHT: if (DEBUG) Log.d(TAG, "gravity: right"); bounds.left = r - v.getMeasuredWidth() - mPeekSize.right; bounds.top = t;/*from ww w .j av a 2s . com*/ bounds.right = r - mPeekSize.right; bounds.bottom = t + v.getMeasuredHeight(); v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom); boundsWithoutPeek = new Rect(bounds); boundsWithoutPeek.offset(mPeekSize.right, 0); mMinScrollX = -bounds.width(); break; case Gravity.TOP: if (DEBUG) Log.d(TAG, "gravity: top"); bounds.left = l; bounds.top = t + mPeekSize.top; bounds.right = v.getMeasuredWidth(); bounds.bottom = t + v.getMeasuredHeight() + mPeekSize.top; v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom); boundsWithoutPeek = new Rect(bounds); boundsWithoutPeek.offset(0, -mPeekSize.top); mMaxScrollY = bounds.height(); break; case Gravity.BOTTOM: if (DEBUG) Log.d(TAG, "gravity: bottom"); bounds.left = l; bounds.top = b - v.getMeasuredHeight() - mPeekSize.bottom; bounds.right = l + v.getMeasuredWidth(); bounds.bottom = b - mPeekSize.bottom; v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom); boundsWithoutPeek = new Rect(bounds); boundsWithoutPeek.offset(0, mPeekSize.bottom); mMinScrollY = -bounds.height(); break; case Gravity.LEFT: if (DEBUG) Log.d(TAG, "gravity: left"); bounds.left = l + mPeekSize.left; bounds.top = t; bounds.right = l + v.getMeasuredWidth() + mPeekSize.left; bounds.bottom = t + v.getMeasuredHeight(); v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom); mMaxScrollX = bounds.width(); boundsWithoutPeek = new Rect(bounds); boundsWithoutPeek.offset(-mPeekSize.left, 0); break; default: if (DEBUG) Log.d(TAG, "gravity: default"); bounds.left = l; bounds.top = t; bounds.right = l + v.getMeasuredWidth(); bounds.bottom = t + v.getMeasuredHeight(); v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom); boundsWithoutPeek = new Rect(bounds); break; } if (DEBUG) { Log.d(TAG, " == VIEW LAYOUT == " + v.toString()); Log.d(TAG, "bounds: " + bounds.left + "," + bounds.top + "," + bounds.right + "," + bounds.bottom); } if (mLayoutBounds.containsKey(v)) mLayoutBounds.remove(v); mLayoutBounds.put(v, bounds); if (mLayoutBoundsWithoutPeek.containsKey(v)) mLayoutBoundsWithoutPeek.remove(v); mLayoutBoundsWithoutPeek.put(v, boundsWithoutPeek); }
From source file:com.actionbarsherlock.internal.widget.ActionBarView.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { int x = getPaddingLeft(); final int y = getPaddingTop(); final int contentHeight = b - t - getPaddingTop() - getPaddingBottom(); if (contentHeight <= 0) { // Nothing to do if we can't see anything. return;// w w w .ja va 2 s . c om } HomeView homeLayout = mExpandedActionView != null ? mExpandedHomeLayout : mHomeLayout; if (homeLayout.getVisibility() != GONE) { final int leftOffset = homeLayout.getLeftOffset(); x += positionChild(homeLayout, x + leftOffset, y, contentHeight) + leftOffset; } if (mExpandedActionView == null) { final boolean showTitle = mTitleLayout != null && mTitleLayout.getVisibility() != GONE && (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0; if (showTitle) { x += positionChild(mTitleLayout, x, y, contentHeight); } switch (mNavigationMode) { case ActionBar.NAVIGATION_MODE_STANDARD: break; case ActionBar.NAVIGATION_MODE_LIST: if (mListNavLayout != null) { if (showTitle) x += mItemPadding; x += positionChild(mListNavLayout, x, y, contentHeight) + mItemPadding; } break; case ActionBar.NAVIGATION_MODE_TABS: if (mTabScrollView != null) { if (showTitle) x += mItemPadding; x += positionChild(mTabScrollView, x, y, contentHeight) + mItemPadding; } break; } } int menuLeft = r - l - getPaddingRight(); if (mMenuView != null && mMenuView.getParent() == this) { positionChildInverse(mMenuView, menuLeft, y, contentHeight); menuLeft -= mMenuView.getMeasuredWidth(); } if (mIndeterminateProgressView != null && mIndeterminateProgressView.getVisibility() != GONE) { positionChildInverse(mIndeterminateProgressView, menuLeft, y, contentHeight); menuLeft -= mIndeterminateProgressView.getMeasuredWidth(); } View customView = null; if (mExpandedActionView != null) { customView = mExpandedActionView; } else if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0 && mCustomNavView != null) { customView = mCustomNavView; } if (customView != null) { ViewGroup.LayoutParams lp = customView.getLayoutParams(); final ActionBar.LayoutParams ablp = lp instanceof ActionBar.LayoutParams ? (ActionBar.LayoutParams) lp : null; final int gravity = ablp != null ? ablp.gravity : DEFAULT_CUSTOM_GRAVITY; final int navWidth = customView.getMeasuredWidth(); int topMargin = 0; int bottomMargin = 0; if (ablp != null) { x += ablp.leftMargin; menuLeft -= ablp.rightMargin; topMargin = ablp.topMargin; bottomMargin = ablp.bottomMargin; } int hgravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK; // See if we actually have room to truly center; if not push against left or right. if (hgravity == Gravity.CENTER_HORIZONTAL) { final int centeredLeft = ((getRight() - getLeft()) - navWidth) / 2; if (centeredLeft < x) { hgravity = Gravity.LEFT; } else if (centeredLeft + navWidth > menuLeft) { hgravity = Gravity.RIGHT; } } else if (gravity == -1) { hgravity = Gravity.LEFT; } int xpos = 0; switch (hgravity) { case Gravity.CENTER_HORIZONTAL: xpos = ((getRight() - getLeft()) - navWidth) / 2; break; case Gravity.LEFT: xpos = x; break; case Gravity.RIGHT: xpos = menuLeft - navWidth; break; } int vgravity = gravity & Gravity.VERTICAL_GRAVITY_MASK; if (gravity == -1) { vgravity = Gravity.CENTER_VERTICAL; } int ypos = 0; switch (vgravity) { case Gravity.CENTER_VERTICAL: final int paddedTop = getPaddingTop(); final int paddedBottom = getBottom() - getTop() - getPaddingBottom(); ypos = ((paddedBottom - paddedTop) - customView.getMeasuredHeight()) / 2; break; case Gravity.TOP: ypos = getPaddingTop() + topMargin; break; case Gravity.BOTTOM: ypos = getHeight() - getPaddingBottom() - customView.getMeasuredHeight() - bottomMargin; break; } final int customWidth = customView.getMeasuredWidth(); customView.layout(xpos, ypos, xpos + customWidth, ypos + customView.getMeasuredHeight()); x += customWidth; } if (mProgressView != null) { mProgressView.bringToFront(); final int halfProgressHeight = mProgressView.getMeasuredHeight() / 2; mProgressView.layout(mProgressBarPadding, -halfProgressHeight, mProgressBarPadding + mProgressView.getMeasuredWidth(), halfProgressHeight); } }
From source file:android.support.v7.widget.Toolbar.java
private int layoutChildLeft(View child, int left, int[] collapsingMargins, int alignmentHeight) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final int l = lp.leftMargin - collapsingMargins[0]; left += Math.max(0, l);//from ww w .j av a 2 s. c o m collapsingMargins[0] = Math.max(0, -l); final int top = getChildTop(child, alignmentHeight); final int childWidth = child.getMeasuredWidth(); child.layout(left, top, left + childWidth, top + child.getMeasuredHeight()); left += childWidth + lp.rightMargin; return left; }
From source file:android.support.v7.widget.Toolbar.java
private int layoutChildRight(View child, int right, int[] collapsingMargins, int alignmentHeight) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final int r = lp.rightMargin - collapsingMargins[1]; right -= Math.max(0, r);//from w ww .j a va 2 s . co m collapsingMargins[1] = Math.max(0, -r); final int top = getChildTop(child, alignmentHeight); final int childWidth = child.getMeasuredWidth(); child.layout(right - childWidth, top, right, top + child.getMeasuredHeight()); right -= childWidth + lp.leftMargin; return right; }