List of usage examples for android.view View getMeasuredHeight
public final int getMeasuredHeight()
From source file:com.aretha.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; int maxChildWidth = 0, maxChildHeight = 0; for (int index = 0; index < count; index++) { View child = getChildAt(index); LayoutParams layoutParams = (LayoutParams) child.getLayoutParams(); switch (layoutParams.role) { case LayoutParams.ROLE_CONTENT: measureChild(child, widthMeasureSpec, heightMeasureSpec); break; case LayoutParams.ROLE_PRIMARY_MENU: case LayoutParams.ROLE_SECONDARY_MENU: measureChild(child, widthMeasureSpec, slideMode == MODE_SLIDE_WINDOW ? MeasureSpec.makeMeasureSpec( MeasureSpec.getSize(heightMeasureSpec) - statusBarHeight, MeasureSpec.getMode(heightMeasureSpec)) : heightMeasureSpec); break; }/* w ww. j a v a 2 s. co m*/ 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)); }
From source file:com.actionbarsherlock.custom.widget.VerticalDrawerLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mInLayout = true;// w w w . j a v a2s . co m 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 childTop; if (checkDrawerViewGravity(child, Gravity.TOP)) { childTop = -childHeight + (int) (childHeight * lp.onScreen); } else { // Bottom; onMeasure checked for us. childTop = b - t - (int) (childHeight * lp.onScreen); } final int vgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK; switch (vgrav) { default: case Gravity.LEFT: { child.layout(lp.leftMargin, childTop, childWidth, childTop + childHeight); break; } case Gravity.RIGHT: { final int width = r - l; child.layout(width - lp.rightMargin - child.getMeasuredWidth(), childTop, width - lp.rightMargin, childTop + childHeight); break; } case Gravity.CENTER_HORIZONTAL: { final int width = r - l; int childLeft = (width - childWidth) / 2; // Offset for margins. If things don't fit right because of // bad measurement before, oh well. if (childLeft < lp.leftMargin) { childLeft = lp.leftMargin; } else if (childLeft + childWidth > width - lp.rightMargin) { childLeft = width - lp.rightMargin - childWidth; } child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight); break; } } if (lp.onScreen == 0) { child.setVisibility(INVISIBLE); } } } mInLayout = false; mFirstLayout = false; }
From source file:com.aidy.bottomdrawerlayout.BottomDrawerLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { Log.i(TAG, "onLayout()"); mInLayout = true;/*from w w w .ja va 2 s. co m*/ final int width = r - l; final int height = b - t; 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 { final int childWidth = child.getMeasuredWidth(); final int childHeight = child.getMeasuredHeight(); int childTop; final float newOffset; if (checkDrawerViewAbsoluteGravity(child, Gravity.BOTTOM)) { childTop = height - (int) (childHeight * lp.onScreen); newOffset = (float) (height - childTop) / childWidth; } else { childTop = -childHeight + (int) (childHeight * lp.onScreen); newOffset = (float) (childHeight + childTop) / childHeight; } final boolean changeOffset = newOffset != lp.onScreen; final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (vgrav) { default: case Gravity.LEFT: { child.layout(lp.leftMargin, childTop, lp.leftMargin + childWidth, childTop + childHeight); break; } case Gravity.RIGHT: { child.layout(width - lp.rightMargin, childTop, width - lp.rightMargin, childTop + childHeight); break; } case Gravity.CENTER_HORIZONTAL: { int childLeft = (width - childWidth) / 2; if (childLeft < lp.leftMargin) { childLeft = lp.leftMargin; } else if (childLeft + childWidth > width - lp.rightMargin) { childLeft = width - lp.rightMargin - childWidth; } 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:com.ecom.consumer.customviews.HorizontalListView.java
/** Loops through each child and positions them onto the screen */ private void positionChildren(final int dx) { int childCount = getChildCount(); if (childCount > 0) { mDisplayOffset += dx;//from ww w. java 2 s .c o m int leftOffset = mDisplayOffset + mDividerWidth; // Loop each child view for (int i = 0; i < childCount; i++) { View child = getChildAt(i); int left = leftOffset + getPaddingLeft(); int top = getPaddingTop(); int right = left + child.getMeasuredWidth(); int bottom = top + child.getMeasuredHeight(); // Layout the child child.layout(left, top, right, bottom); // Increment our offset by added child's size and divider width leftOffset += child.getMeasuredWidth() + mDividerWidth; } } }
From source file:com.android.mail.browse.ConversationContainer.java
private void positionOverlay(int adapterIndex, int overlayTopY, int overlayBottomY, boolean postAddView) { final OverlayView overlay = mOverlayViews.get(adapterIndex); final ConversationOverlayItem item = mOverlayAdapter.getItem(adapterIndex); // save off the item's current top for later snap calculations item.setTop(overlayTopY);//from w w w .j a v a 2 s .c o m // is the overlay visible and does it have non-zero height? if (overlayTopY != overlayBottomY && overlayBottomY > mOffsetY && overlayTopY < mOffsetY + getHeight()) { View overlayView = overlay != null ? overlay.view : null; // show and/or move overlay if (overlayView == null) { overlayView = addOverlayView(adapterIndex, postAddView); ViewCompat.setLayoutDirection(overlayView, ViewCompat.getLayoutDirection(this)); measureOverlayView(overlayView); item.markMeasurementValid(); traceLayout("show/measure overlay %d", adapterIndex); } else { traceLayout("move overlay %d", adapterIndex); if (!item.isMeasurementValid()) { item.rebindView(overlayView); measureOverlayView(overlayView); item.markMeasurementValid(); traceLayout("and (re)measure overlay %d, old/new heights=%d/%d", adapterIndex, overlayView.getHeight(), overlayView.getMeasuredHeight()); } } traceLayout("laying out overlay %d with h=%d", adapterIndex, overlayView.getMeasuredHeight()); final int childBottom = overlayTopY + overlayView.getMeasuredHeight(); layoutOverlay(overlayView, overlayTopY, childBottom); mAdditionalBottomBorderOverlayTop = (childBottom > mAdditionalBottomBorderOverlayTop) ? childBottom : mAdditionalBottomBorderOverlayTop; } else { // hide overlay if (overlay != null) { traceLayout("hide overlay %d", adapterIndex); onOverlayScrolledOff(adapterIndex, overlay, overlayTopY, overlayBottomY); } else { traceLayout("ignore non-visible overlay %d", adapterIndex); } mAdditionalBottomBorderOverlayTop = (overlayBottomY > mAdditionalBottomBorderOverlayTop) ? overlayBottomY : mAdditionalBottomBorderOverlayTop; } if (overlayTopY <= mOffsetY && item.canPushSnapHeader()) { if (mSnapIndex == -1) { mSnapIndex = adapterIndex; } else if (adapterIndex > mSnapIndex) { mSnapIndex = adapterIndex; } } }
From source file:com.abewy.android.apps.klyph.widget.KlyphDrawerLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mInLayout = true;// w w w . jav a2 s .com 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 (checkDrawerViewGravity(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, 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:com.apptentive.android.sdk.view.ApptentiveNestedScrollView.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if (!mFillViewport) { return;//from w w w.j a v a 2 s . com } final int heightMode = MeasureSpec.getMode(heightMeasureSpec); if (heightMode == MeasureSpec.UNSPECIFIED) { return; } if (getChildCount() > 0) { final View child = getChildAt(0); int height = getMeasuredHeight(); if (child.getMeasuredHeight() < height) { final FrameLayout.LayoutParams lp = (LayoutParams) child.getLayoutParams(); int childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec, getPaddingLeft() + getPaddingRight(), lp.width); height -= getPaddingTop(); height -= getPaddingBottom(); int childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); child.measure(childWidthMeasureSpec, childHeightMeasureSpec); } } }
From source file:com.cmbb.smartmarket.widget.NestedScrollView.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if (!mFillViewport) { return;//from w ww . ja va2 s . c o m } final int heightMode = MeasureSpec.getMode(heightMeasureSpec); if (heightMode == MeasureSpec.UNSPECIFIED) { return; } if (getChildCount() > 0) { final View child = getChildAt(0); int height = getMeasuredHeight(); if (child.getMeasuredHeight() < height) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); int childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec, getPaddingLeft() + getPaddingRight(), lp.width); height -= getPaddingTop(); height -= getPaddingBottom(); int childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); child.measure(childWidthMeasureSpec, childHeightMeasureSpec); } } }
From source file:com.daiv.android.twitter.manipulations.widgets.NotificationDrawerLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mInLayout = true;//from ww w . j a v a 2 s . c om 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)) { try { child.layout(lp.leftMargin, lp.topMargin, lp.leftMargin + child.getMeasuredWidth(), lp.topMargin + child.getMeasuredHeight()); } catch (Exception e) { } } 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 (checkDrawerViewGravity(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, 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.Toolbar.java
/** * Returns true if the Toolbar is collapsible and has no child views with a measured size > 0. */// www.j ava 2 s.c o m private boolean shouldCollapse() { if (!mCollapsible) return false; final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (shouldLayout(child) && child.getMeasuredWidth() > 0 && child.getMeasuredHeight() > 0) { return false; } } return true; }