Java Code Examples for android.view.View#getMeasuredWidth()

The following examples show how to use android.view.View#getMeasuredWidth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HorizontalListView.java    From MyBookshelf with GNU General Public License v3.0 6 votes vote down vote up
private void removeNonVisibleItems(final int dx) {
    View child = getChildAt(0);
    while(child != null && child.getRight() + dx <= 0) {
        mDisplayOffset += child.getMeasuredWidth();
        mRemovedViewQueue.offer(child);
        removeViewInLayout(child);
        mLeftViewIndex++;
        child = getChildAt(0);

    }

    child = getChildAt(getChildCount()-1);
    while(child != null && child.getLeft() + dx >= getWidth()) {
        mRemovedViewQueue.offer(child);
        removeViewInLayout(child);
        mRightViewIndex--;
        child = getChildAt(getChildCount()-1);
    }
}
 
Example 2
Source File: InfoBarLayout.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Computes properties of the next group of Views to assign to rows.
 * @param startIndex Index of the first child in the group.
 * @return GroupInfo containing information about the current group.
 */
private GroupInfo getNextGroup(int startIndex) {
    GroupInfo groupInfo = new GroupInfo();
    groupInfo.endIndex = startIndex;

    final int childCount = getChildCount();
    int currentChildIndex = startIndex;
    while (groupInfo.endIndex < childCount) {
        final View groupChild = getChildAt(groupInfo.endIndex);
        if (groupChild.getVisibility() != View.GONE) {
            groupInfo.hasButton |= isButton(groupChild);
            groupInfo.width += groupChild.getMeasuredWidth();
            groupInfo.greatestMemberWidth =
                    Math.max(groupInfo.greatestMemberWidth, groupChild.getMeasuredWidth());
            groupInfo.numViews++;
        }
        groupInfo.endIndex++;

        LayoutParams params = (LayoutParams) groupChild.getLayoutParams();
        if (!params.isGroupedWithNextView) break;
    }

    return groupInfo;
}
 
Example 3
Source File: TranslationLayout.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

	measureChildren(widthMeasureSpec, heightMeasureSpec);

	int width = 0;
	int height = 0;		

	int count = getChildCount();
	for (int i = 0; i < count; i++) {
		View child = getChildAt(i);
		if (child.getVisibility() != GONE) {
			TranslationLayout.LayoutParams lp = (TranslationLayout.LayoutParams) child.getLayoutParams();
			// get anchor offsets
			float aX = (lp.anchorX == null) ? anchorX : lp.anchorX;
            float aY = (lp.anchorY == null) ? anchorY : lp.anchorY;
            // offset dimensions by anchor values
            int computedWidth = (int) (child.getMeasuredWidth() * aX);
            int computedHeight = (int) (child.getMeasuredHeight() * aY);
            // get offset position
            int scaledX = (int) (0.5 + (lp.x * scale));
            int scaledY = (int) (0.5 + (lp.y * scale));
            // add computed dimensions to actual position
            int right = scaledX + computedWidth;
			int bottom = scaledY + computedHeight;
			// if it's larger, use that
			width = Math.max(width, right);
			height = Math.max(height, bottom);
		}
	}

	height = Math.max(height, getSuggestedMinimumHeight());
	width = Math.max(width, getSuggestedMinimumWidth());
	width = resolveSize(width, widthMeasureSpec);
	height = resolveSize(height, heightMeasureSpec);
	setMeasuredDimension(width, height);
	
}
 
Example 4
Source File: LessonB.java    From SchoolQuest with GNU General Public License v3.0 5 votes vote down vote up
private boolean isViewOverlapping(View firstView, View secondView) {
    int[] firstPosition = new int[2];
    int[] secondPosition = new int[2];

    firstView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
    firstView.getLocationOnScreen(firstPosition);
    secondView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
    secondView.getLocationOnScreen(secondPosition);

    float firstWidth = firstView.getMeasuredWidth() * firstView.getScaleX();
    float secondWidth = secondView.getMeasuredWidth() * secondView.getScaleX();

    return firstPosition[0] < secondPosition[0] + secondWidth
            && firstPosition[0] + firstWidth > secondPosition[0];
}
 
Example 5
Source File: FixedLayout.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

    measureChildren(widthMeasureSpec, heightMeasureSpec);

    int width = 0;
    int height = 0;

    int count = getChildCount();
    for (int i = 0; i < count; i++) {
        View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            FixedLayout.LayoutParams lp = (FixedLayout.LayoutParams) child.getLayoutParams();
            int right = lp.x + child.getMeasuredWidth();
            int bottom = lp.y + child.getMeasuredHeight();
            width = Math.max(width, right);
            height = Math.max(height, bottom);
        }
    }

    height = Math.max(height, getSuggestedMinimumHeight());
    width = Math.max(width, getSuggestedMinimumWidth());
    width = resolveSize(width, widthMeasureSpec);
    height = resolveSize(height, heightMeasureSpec);
    setMeasuredDimension(width, height);

}
 
Example 6
Source File: BlurConfig.java    From base-module with Apache License 2.0 5 votes vote down vote up
public Builder(Activity activity) {
    checkNull(activity, "activity");
    mBlurConfig = new BlurConfig(SOURCE_ACTIVITY);
    mBlurConfig.context = new WeakReference<Context>(activity.getApplicationContext());
    mBlurConfig.source = new WeakReference<Object>(activity);
    View view = activity.getWindow().getDecorView().getRootView();
    mBlurConfig.width = view.getMeasuredWidth();
    mBlurConfig.height = view.getMeasuredHeight();
}
 
Example 7
Source File: FlowLayout.java    From Bailan with Apache License 2.0 5 votes vote down vote up
/**
 * 添加一个孩子
 *
 * @param view
 */
public void addView(View view) {
    views.add(view);
    mWidth += view.getMeasuredWidth();
    int childHeight = view.getMeasuredHeight();
    // 高度等于一行中最高的View
    mHeight = mHeight < childHeight ? childHeight : mHeight;
}
 
Example 8
Source File: FlowTagLayout.java    From FlowTag with Apache License 2.0 5 votes vote down vote up
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {

    int flowWidth = getWidth();

    int childLeft = 0;
    int childTop = 0;

    //遍历子控件,记录每个子view的位置
    for (int i = 0, childCount = getChildCount(); i < childCount; i++) {
        View childView = getChildAt(i);

        //跳过View.GONE的子View
        if (childView.getVisibility() == View.GONE) {
            continue;
        }

        //获取到测量的宽和高
        int childWidth = childView.getMeasuredWidth();
        int childHeight = childView.getMeasuredHeight();

        //因为子View可能设置margin,这里要加上margin的距离
        MarginLayoutParams mlp = (MarginLayoutParams) childView.getLayoutParams();

        if (childLeft + mlp.leftMargin + childWidth + mlp.rightMargin > flowWidth) {
            //换行处理
            childTop += (mlp.topMargin + childHeight + mlp.bottomMargin);
            childLeft = 0;
        }
        //布局
        int left = childLeft + mlp.leftMargin;
        int top = childTop + mlp.topMargin;
        int right = childLeft + mlp.leftMargin + childWidth;
        int bottom = childTop + mlp.topMargin + childHeight;
        childView.layout(left, top, right, bottom);

        childLeft += (mlp.leftMargin + childWidth + mlp.rightMargin);
    }
}
 
Example 9
Source File: MySlidingDrawer.java    From slidingtabs with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

    int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
    int widthSpecSize =  MeasureSpec.getSize(widthMeasureSpec);

    int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
    int heightSpecSize =  MeasureSpec.getSize(heightMeasureSpec);

    if (widthSpecMode == MeasureSpec.UNSPECIFIED || heightSpecMode == MeasureSpec.UNSPECIFIED) {
        throw new RuntimeException("SlidingDrawer cannot have UNSPECIFIED dimensions");
    }

    final View handle = getHandle();
    final View content = getContent();
    measureChild(handle, widthMeasureSpec, heightMeasureSpec);

    if (mVertical) {
        int height = heightSpecSize - handle.getMeasuredHeight() - mTopOffset;
        content.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(height, heightSpecMode));
        heightSpecSize = handle.getMeasuredHeight() + mTopOffset + content.getMeasuredHeight();
        widthSpecSize = content.getMeasuredWidth();
        if (handle.getMeasuredWidth() > widthSpecSize) widthSpecSize = handle.getMeasuredWidth();
    }
    else {
        int width = widthSpecSize - handle.getMeasuredWidth() - mTopOffset;
        getContent().measure(MeasureSpec.makeMeasureSpec(width, widthSpecMode), heightMeasureSpec);
        widthSpecSize = handle.getMeasuredWidth() + mTopOffset + content.getMeasuredWidth();
        heightSpecSize = content.getMeasuredHeight();
        if (handle.getMeasuredHeight() > heightSpecSize) heightSpecSize = handle.getMeasuredHeight();
    }

    setMeasuredDimension(widthSpecSize, heightSpecSize);
}
 
Example 10
Source File: BasePopup.java    From EasyPopup with Apache License 2.0 5 votes vote down vote up
/**
 * 是否需要测量 contentView的大小
 * 如果需要重新测量并为宽高赋值
 * 注:此方法获取的宽高可能不准确 MATCH_PARENT时无法获取准确的宽高
 */
private void measureContentView() {
    final View contentView = getContentView();
    if (mWidth <= 0 || mHeight <= 0) {
        //测量大小
        contentView.measure(0, View.MeasureSpec.UNSPECIFIED);
        if (mWidth <= 0) {
            mWidth = contentView.getMeasuredWidth();
        }
        if (mHeight <= 0) {
            mHeight = contentView.getMeasuredHeight();
        }
    }
}
 
Example 11
Source File: BaselineLayout.java    From PagerBottomTabStrip with Apache License 2.0 5 votes vote down vote up
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    final int count = getChildCount();
    final int parentLeft = getPaddingLeft();
    final int parentRight = right - left - getPaddingRight();
    final int parentContentWidth = parentRight - parentLeft;
    final int parentTop = getPaddingTop();

    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() == GONE) {
            continue;
        }

        final int width = child.getMeasuredWidth();
        final int height = child.getMeasuredHeight();

        final int childLeft = parentLeft + (parentContentWidth - width) / 2;
        final int childTop;
        if (mBaseline != -1 && child.getBaseline() != -1) {
            childTop = parentTop + mBaseline - child.getBaseline();
        } else {
            childTop = parentTop;
        }

        child.layout(childLeft, childTop, childLeft + width, childTop + height);
    }
}
 
Example 12
Source File: SlidingDrawer.java    From Linphone4Android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
	int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
	int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec);

	int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
	int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec);

	if (widthSpecMode == MeasureSpec.UNSPECIFIED
			|| heightSpecMode == MeasureSpec.UNSPECIFIED) {
		throw new RuntimeException(
				"SlidingDrawer cannot have UNSPECIFIED dimensions");
	}

	final View handle = mHandle;
	measureChild(handle, widthMeasureSpec, heightMeasureSpec);

	if (mVertical) {
		int height = heightSpecSize - handle.getMeasuredHeight()
				- mTopOffset;
		mContent.measure(MeasureSpec.makeMeasureSpec(widthSpecSize,
				MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height,
				MeasureSpec.AT_MOST));
	} else {
		int width = widthSpecSize - handle.getMeasuredWidth() - mTopOffset;
		mContent.measure(MeasureSpec.makeMeasureSpec(width,
				MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(
				heightSpecSize, MeasureSpec.EXACTLY));
	}

	setMeasuredDimension(widthSpecSize, heightSpecSize);
}
 
Example 13
Source File: FlowLayout.java    From Aurora with Apache License 2.0 4 votes vote down vote up
/**
 * 给孩子布局
 *
 * @param offsetLeft
 * @param offsetTop
 */
public void layout(int offsetLeft, int offsetTop) {
    // 给孩子布局

    int currentLeft = offsetLeft;

    int size = mViews.size();
    // 判断已经使用的宽度是否小于最大的宽度
    float extra = 0;
    float widthAvg = 0;
    if (mMaxWidth > mUsedWidth) {
        extra = mMaxWidth - mUsedWidth;
        widthAvg = extra / size;
    }

    for (int i = 0; i < size; i++) {
        View view = mViews.get(i);
        int viewWidth = view.getMeasuredWidth();
        int viewHeight = view.getMeasuredHeight();

        // 判断是否有富余
        if (widthAvg != 0) {
            // 改变宽度
            int newWidth = (int) (viewWidth + widthAvg + 0.5f);
            int widthMeasureSpec = MeasureSpec.makeMeasureSpec(newWidth, MeasureSpec.EXACTLY);
            int heightMeasureSpec = MeasureSpec.makeMeasureSpec(viewHeight, MeasureSpec.EXACTLY);
            view.measure(widthMeasureSpec, heightMeasureSpec);

            viewWidth = view.getMeasuredWidth();
            viewHeight = view.getMeasuredHeight();
        }

        // 布局
        int left = currentLeft;
        int top = (int) (offsetTop + (mHeigth - viewHeight) / 2 +
                0.5f);
        // int top = offsetTop;
        int right = left + viewWidth;
        int bottom = top + viewHeight;
        if (i==0){
            view.layout(left+6, top, right, bottom);
        }else {
            view.layout(left, top, right, bottom);
        }


        currentLeft += viewWidth + mHorizontalSpace;
    }
}
 
Example 14
Source File: FilterUsersActivity.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int count = getChildCount();
    int width = MeasureSpec.getSize(widthMeasureSpec);
    int maxWidth = width - AndroidUtilities.dp(26);
    int currentLineWidth = 0;
    int y = AndroidUtilities.dp(10);
    int allCurrentLineWidth = 0;
    int allY = AndroidUtilities.dp(10);
    int x;
    for (int a = 0; a < count; a++) {
        View child = getChildAt(a);
        if (!(child instanceof GroupCreateSpan)) {
            continue;
        }
        child.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(32), MeasureSpec.EXACTLY));
        if (child != removingSpan && currentLineWidth + child.getMeasuredWidth() > maxWidth) {
            y += child.getMeasuredHeight() + AndroidUtilities.dp(8);
            currentLineWidth = 0;
        }
        if (allCurrentLineWidth + child.getMeasuredWidth() > maxWidth) {
            allY += child.getMeasuredHeight() + AndroidUtilities.dp(8);
            allCurrentLineWidth = 0;
        }
        x = AndroidUtilities.dp(13) + currentLineWidth;
        if (!animationStarted) {
            if (child == removingSpan) {
                child.setTranslationX(AndroidUtilities.dp(13) + allCurrentLineWidth);
                child.setTranslationY(allY);
            } else if (removingSpan != null) {
                if (child.getTranslationX() != x) {
                    animators.add(ObjectAnimator.ofFloat(child, View.TRANSLATION_X, x));
                }
                if (child.getTranslationY() != y) {
                    animators.add(ObjectAnimator.ofFloat(child, View.TRANSLATION_Y, y));
                }
            } else {
                child.setTranslationX(x);
                child.setTranslationY(y);
            }
        }
        if (child != removingSpan) {
            currentLineWidth += child.getMeasuredWidth() + AndroidUtilities.dp(9);
        }
        allCurrentLineWidth += child.getMeasuredWidth() + AndroidUtilities.dp(9);
    }
    int minWidth;
    if (AndroidUtilities.isTablet()) {
        minWidth = AndroidUtilities.dp(530 - 26 - 18 - 57 * 2) / 3;
    } else {
        minWidth = (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) - AndroidUtilities.dp(26 + 18 + 57 * 2)) / 3;
    }
    if (maxWidth - currentLineWidth < minWidth) {
        currentLineWidth = 0;
        y += AndroidUtilities.dp(32 + 8);
    }
    if (maxWidth - allCurrentLineWidth < minWidth) {
        allY += AndroidUtilities.dp(32 + 8);
    }
    editText.measure(MeasureSpec.makeMeasureSpec(maxWidth - currentLineWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(32), MeasureSpec.EXACTLY));
    if (!animationStarted) {
        int currentHeight = allY + AndroidUtilities.dp(32 + 10);
        int fieldX = currentLineWidth + AndroidUtilities.dp(16);
        fieldY = y;
        if (currentAnimation != null) {
            int resultHeight = y + AndroidUtilities.dp(32 + 10);
            if (containerHeight != resultHeight) {
                animators.add(ObjectAnimator.ofInt(FilterUsersActivity.this, "containerHeight", resultHeight));
            }
            if (editText.getTranslationX() != fieldX) {
                animators.add(ObjectAnimator.ofFloat(editText, View.TRANSLATION_X, fieldX));
            }
            if (editText.getTranslationY() != fieldY) {
                animators.add(ObjectAnimator.ofFloat(editText, View.TRANSLATION_Y, fieldY));
            }
            editText.setAllowDrawCursor(false);
            currentAnimation.playTogether(animators);
            currentAnimation.start();
            animationStarted = true;
        } else {
            containerHeight = currentHeight;
            editText.setTranslationX(fieldX);
            editText.setTranslationY(fieldY);
        }
    } else if (currentAnimation != null) {
        if (!ignoreScrollEvent && removingSpan == null) {
            editText.bringPointIntoView(editText.getSelectionStart());
        }
    }
    setMeasuredDimension(width, containerHeight);
}
 
Example 15
Source File: X8MapPointMarkerViewGroup.java    From FimiX8-RE with MIT License 4 votes vote down vote up
public void onLayoutForTyp2(boolean changed, int l, int t, int r, int b) {
    int countH = 0;
    for (int i = 0; i < getChildCount(); i++) {
        View child = getChildAt(i);
        int left = 0;
        int top = 0;
        int right = 0;
        int bottom = 0;
        int w = child.getMeasuredWidth();
        int h = child.getMeasuredHeight();
        if (i == 0) {
            if (this.tempWidth == w) {
                right = 0 + w;
                bottom = 0 + h;
            } else {
                left = (this.tempWidth - w) / 2;
                right = (this.tempWidth + w) / 2;
                bottom = 0 + h;
            }
            countH = bottom;
        } else if (i == 1) {
            if (this.tempWidth == w) {
                right = 0 + w;
                top = countH + this.magin2;
                bottom = top + h;
            } else {
                left = (this.tempWidth - w) / 2;
                right = (this.tempWidth + w) / 2;
                top = countH + this.magin2;
                bottom = top + h;
            }
            countH = bottom;
        } else if (i == 2) {
            left = (this.tempWidth - w) / 2;
            right = (this.tempWidth + w) / 2;
            int tmeph = getChildAt(1).getMeasuredHeight();
            top = (int) ((((float) countH) - (0.5f * ((float) tmeph))) - (0.5f * ((float) h)));
            bottom = (int) ((((float) countH) - (0.5f * ((float) tmeph))) + (0.5f * ((float) h)));
            float d = (((float) countH) - (0.5f * ((float) tmeph))) / ((float) getMeasuredHeight());
        }
        child.layout(left, top, right, bottom);
    }
}
 
Example 16
Source File: SingleLineFlowLayout.java    From ClockView with Apache License 2.0 4 votes vote down vote up
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int paddingLeft = getPaddingLeft();
    int paddingRight = getPaddingRight();
    int paddingTop = getPaddingTop();
    int paddingBottom = getPaddingBottom();

    int childStartLayoutX = paddingLeft;
    int childStartLayoutY = paddingTop;

    int widthUsed = paddingLeft + paddingRight;

    int childMaxHeight = 0;

    int childCount = getChildCount();

    for (int i = 0; i < childCount; i++) {
        View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            int childNeededWidth, childNeedHeight;
            int left = 0, top = 0, right = 0, bottom = 0;

            int childMeasuredWidth = child.getMeasuredWidth();
            int childMeasuredHeight = child.getMeasuredHeight();

            LayoutParams childLayoutParams = (LayoutParams) child.getLayoutParams();
            MarginLayoutParams marginLayoutParams = childLayoutParams;
            int childLeftMargin = marginLayoutParams.leftMargin;
            int childTopMargin = marginLayoutParams.topMargin;
            int childRightMargin = marginLayoutParams.rightMargin;
            int childBottomMargin = marginLayoutParams.bottomMargin;
            childNeededWidth = childLeftMargin + childRightMargin + childMeasuredWidth + horizontalSpacing;
            childNeedHeight = childTopMargin + childBottomMargin + childMeasuredHeight;

            if (widthUsed + childNeededWidth <= r - l) {
                if (childNeedHeight > childMaxHeight) {
                    childMaxHeight = childNeedHeight;
                }
                left = childStartLayoutX + childLeftMargin;
                top = childStartLayoutY + childTopMargin;
                right = left + childMeasuredWidth;
                bottom = top + childMeasuredHeight;
                widthUsed += childNeededWidth;
                childStartLayoutX += childNeededWidth;
            } else {
                isFull = true;
            }
            child.layout(left, top, right, bottom);
        }
    }
}
 
Example 17
Source File: FloatingActionMenu.java    From FloatingActionButton with Apache License 2.0 4 votes vote down vote up
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int buttonsHorizontalCenter = mLabelsPosition == LABELS_POSITION_LEFT
            ? r - l - mMaxButtonWidth / 2 - getPaddingRight()
            : mMaxButtonWidth / 2 + getPaddingLeft();
    boolean openUp = mOpenDirection == OPEN_UP;

    int menuButtonTop = openUp
            ? b - t - mMenuButton.getMeasuredHeight() - getPaddingBottom()
            : getPaddingTop();
    int menuButtonLeft = buttonsHorizontalCenter - mMenuButton.getMeasuredWidth() / 2;

    mMenuButton.layout(menuButtonLeft, menuButtonTop, menuButtonLeft + mMenuButton.getMeasuredWidth(),
            menuButtonTop + mMenuButton.getMeasuredHeight());

    int imageLeft = buttonsHorizontalCenter - mImageToggle.getMeasuredWidth() / 2;
    int imageTop = menuButtonTop + mMenuButton.getMeasuredHeight() / 2 - mImageToggle.getMeasuredHeight() / 2;

    mImageToggle.layout(imageLeft, imageTop, imageLeft + mImageToggle.getMeasuredWidth(),
            imageTop + mImageToggle.getMeasuredHeight());

    int nextY = openUp
            ? menuButtonTop + mMenuButton.getMeasuredHeight() + mButtonSpacing
            : menuButtonTop;

    for (int i = mButtonsCount - 1; i >= 0; i--) {
        View child = getChildAt(i);

        if (child == mImageToggle) continue;

        FloatingActionButton fab = (FloatingActionButton) child;

        if (fab.getVisibility() == GONE) continue;

        int childX = buttonsHorizontalCenter - fab.getMeasuredWidth() / 2;
        int childY = openUp ? nextY - fab.getMeasuredHeight() - mButtonSpacing : nextY;

        if (fab != mMenuButton) {
            fab.layout(childX, childY, childX + fab.getMeasuredWidth(),
                    childY + fab.getMeasuredHeight());

            if (!mIsMenuOpening) {
                fab.hide(false);
            }
        }

        View label = (View) fab.getTag(R.id.fab_label);
        if (label != null) {
            int labelsOffset = (mUsingMenuLabel ? mMaxButtonWidth / 2 : fab.getMeasuredWidth() / 2) + mLabelsMargin;
            int labelXNearButton = mLabelsPosition == LABELS_POSITION_LEFT
                    ? buttonsHorizontalCenter - labelsOffset
                    : buttonsHorizontalCenter + labelsOffset;

            int labelXAwayFromButton = mLabelsPosition == LABELS_POSITION_LEFT
                    ? labelXNearButton - label.getMeasuredWidth()
                    : labelXNearButton + label.getMeasuredWidth();

            int labelLeft = mLabelsPosition == LABELS_POSITION_LEFT
                    ? labelXAwayFromButton
                    : labelXNearButton;

            int labelRight = mLabelsPosition == LABELS_POSITION_LEFT
                    ? labelXNearButton
                    : labelXAwayFromButton;

            int labelTop = childY - mLabelsVerticalOffset + (fab.getMeasuredHeight()
                    - label.getMeasuredHeight()) / 2;

            label.layout(labelLeft, labelTop, labelRight, labelTop + label.getMeasuredHeight());

            if (!mIsMenuOpening) {
                label.setVisibility(INVISIBLE);
            }
        }

        nextY = openUp
                ? childY - mButtonSpacing
                : childY + child.getMeasuredHeight() + mButtonSpacing;
    }
}
 
Example 18
Source File: SwipeHelper.java    From HeadsUp with GNU General Public License v2.0 4 votes vote down vote up
private float getSize(View v) {
    return mSwipeDirection == X ? v.getMeasuredWidth() :
            v.getMeasuredHeight();
}
 
Example 19
Source File: CustomLayout.java    From Building-Android-UIs-with-Custom-Views with MIT License 4 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if(getWidth() == 0) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        return;
    }

    int count = getChildCount();

    int rowHeight = 0;
    int maxWidth = 0;
    int maxHeight = 0;
    int left = 0;
    int top = 0;

    for(int i = 0; i < count; i++) {
        View child = getChildAt(i);
        measureChild(child, widthMeasureSpec, heightMeasureSpec);

        int childWidth = child.getMeasuredWidth();
        int childHeight = child.getMeasuredHeight();

        // if child fits in this row put it there
        if(left + childWidth < getWidth()) {
            left += childWidth;
        } else {
            // otherwise put it on next row
            if(left > maxWidth) maxWidth = left;
            left = 0;
            top += rowHeight;
            rowHeight = 0;
        }

        // update maximum row height
        if(childHeight > rowHeight) rowHeight = childHeight;
    }

    if(left > maxWidth) maxWidth = left;
    maxHeight = top + rowHeight;

    setMeasuredDimension(getMeasure(widthMeasureSpec, maxWidth), getMeasure(heightMeasureSpec, maxHeight));
}
 
Example 20
Source File: WidgetUtils.java    From styT with Apache License 2.0 2 votes vote down vote up
/**
 * 测量控件宽度
 *
 * @param view
 * @return
 */
public static int getMeasuredWidth(View view) {
    measureView(view);
    return view.getMeasuredWidth();
}