/// <summary> /// Helper for makeAndAddView to set the position of a view /// and fill out its layout paramters. /// </summary> /// <remarks> /// Helper for makeAndAddView to set the position of a view /// and fill out its layout paramters. /// </remarks> /// <param name="child">The view to position</param> private void setUpChild(android.view.View child) { // Respect layout params that are already in the view. Otherwise // make some up... android.view.ViewGroup.LayoutParams lp = child.getLayoutParams(); if (lp == null) { lp = generateDefaultLayoutParams(); } addViewInLayout(child, 0, lp); child.setSelected(hasFocus()); // Get measure specs int childHeightSpec = android.view.ViewGroup.getChildMeasureSpec(mHeightMeasureSpec , mSpinnerPadding.top + mSpinnerPadding.bottom, lp.height); int childWidthSpec = android.view.ViewGroup.getChildMeasureSpec(mWidthMeasureSpec , mSpinnerPadding.left + mSpinnerPadding.right, lp.width); // Measure child child.measure(childWidthSpec, childHeightSpec); int childLeft; int childRight; // Position vertically based on gravity setting int childTop = mSpinnerPadding.top + ((getMeasuredHeight() - mSpinnerPadding.bottom - mSpinnerPadding.top - child.getMeasuredHeight()) / 2); int childBottom = childTop + child.getMeasuredHeight(); int width = child.getMeasuredWidth(); childLeft = 0; childRight = childLeft + width; child.layout(childLeft, childTop, childRight, childBottom); }
protected internal virtual int positionChildInverse(android.view.View child, int x, int y, int contentHeight) { int childWidth = child.getMeasuredWidth(); int childHeight = child.getMeasuredHeight(); int childTop = y + (contentHeight - childHeight) / 2; child.layout(x - childWidth, childTop, x, childTop + childHeight); return(childWidth); }
protected internal override void onLayout(bool changed, int l, int t, int r, int b) { int count = getChildCount(); { for (int i = 0; i < count; i++) { android.view.View child = getChildAt(i); if (child.getVisibility() != GONE) { android.widget.AbsoluteLayout.LayoutParams lp = (android.widget.AbsoluteLayout.LayoutParams )child.getLayoutParams(); int childLeft = mPaddingLeft + lp.x; int childTop = mPaddingTop + lp.y; child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(), childTop + child.getMeasuredHeight()); } } } }
protected internal override void onLayout(bool changed, int left, int top, int right , int bottom) { if (!mFormatItems) { base.onLayout(changed, left, top, right, bottom); return; } int childCount = getChildCount(); int midVertical = (top + bottom) / 2; int dividerWidth = getDividerWidth(); int overflowWidth = 0; int nonOverflowWidth = 0; int nonOverflowCount = 0; int widthRemaining = right - left - getPaddingRight() - getPaddingLeft(); bool hasOverflow = false; { for (int i = 0; i < childCount; i++) { android.view.View v = getChildAt(i); if (v.getVisibility() == GONE) { continue; } [email protected] p = ([email protected] .LayoutParams)v.getLayoutParams(); if (p.isOverflowButton) { overflowWidth = v.getMeasuredWidth(); if (hasDividerBeforeChildAt(i)) { overflowWidth += dividerWidth; } int height = v.getMeasuredHeight(); int r = getWidth() - getPaddingRight() - p.rightMargin; int l = r - overflowWidth; int t = midVertical - (height / 2); int b = t + height; v.layout(l, t, r, b); widthRemaining -= overflowWidth; hasOverflow = true; } else { int size = v.getMeasuredWidth() + p.leftMargin + p.rightMargin; nonOverflowWidth += size; widthRemaining -= size; if (hasDividerBeforeChildAt(i)) { nonOverflowWidth += dividerWidth; } nonOverflowCount++; } } } if (childCount == 1 && !hasOverflow) { // Center a single child android.view.View v = getChildAt(0); int width = v.getMeasuredWidth(); int height = v.getMeasuredHeight(); int midHorizontal = (right - left) / 2; int l = midHorizontal - width / 2; int t = midVertical - height / 2; v.layout(l, t, l + width, t + height); return; } int spacerCount = nonOverflowCount - (hasOverflow ? 0 : 1); int spacerSize = System.Math.Max(0, spacerCount > 0 ? widthRemaining / spacerCount : 0); int startLeft = getPaddingLeft(); { for (int i_1 = 0; i_1 < childCount; i_1++) { android.view.View v = getChildAt(i_1); [email protected] lp = ([email protected] .LayoutParams)v.getLayoutParams(); if (v.getVisibility() == GONE || lp.isOverflowButton) { continue; } startLeft += lp.leftMargin; int width = v.getMeasuredWidth(); int height = v.getMeasuredHeight(); int t = midVertical - height / 2; v.layout(startLeft, t, startLeft + width, t + height); startLeft += width + lp.rightMargin + spacerSize; } } }
protected internal override void onLayout(bool changed, int l, int t, int r, int b) { base.onLayout(changed, l, t, r, b); bool hasTabs = mTabContainer != null && mTabContainer.getVisibility() != GONE; if (mTabContainer != null && mTabContainer.getVisibility() != GONE) { int containerHeight = getMeasuredHeight(); int tabHeight = mTabContainer.getMeasuredHeight(); if ((mActionBarView.getDisplayOptions() & android.app.ActionBar.DISPLAY_SHOW_HOME ) == 0) { // Not showing home, put tabs on top. int count = getChildCount(); { for (int i = 0; i < count; i++) { android.view.View child = getChildAt(i); if (child == mTabContainer) { continue; } if (!mActionBarView.isCollapsed()) { child.offsetTopAndBottom(tabHeight); } } } mTabContainer.layout(l, 0, r, tabHeight); } else { mTabContainer.layout(l, containerHeight - tabHeight, r, containerHeight); } } bool needsInvalidate = false; if (mIsSplit) { if (mSplitBackground != null) { mSplitBackground.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight()); needsInvalidate = true; } } else { if (mBackground != null) { mBackground.setBounds(mActionBarView.getLeft(), mActionBarView.getTop(), mActionBarView .getRight(), mActionBarView.getBottom()); needsInvalidate = true; } if ((mIsStacked = hasTabs && mStackedBackground != null)) { mStackedBackground.setBounds(mTabContainer.getLeft(), mTabContainer.getTop(), mTabContainer .getRight(), mTabContainer.getBottom()); needsInvalidate = true; } } if (needsInvalidate) { invalidate(); } }
protected internal override void onLayout(bool changed, int left, int top, int right , int bottom) { int count = getChildCount(); int parentLeft = getPaddingLeftWithForeground(); int parentRight = right - left - getPaddingRightWithForeground(); int parentTop = getPaddingTopWithForeground(); int parentBottom = bottom - top - getPaddingBottomWithForeground(); mForegroundBoundsChanged = true; { for (int i = 0; i < count; i++) { android.view.View child = getChildAt(i); if (child.getVisibility() != GONE) { android.widget.FrameLayout.LayoutParams lp = (android.widget.FrameLayout.LayoutParams )child.getLayoutParams(); int width = child.getMeasuredWidth(); int height = child.getMeasuredHeight(); int childLeft; int childTop; int gravity = lp.gravity; if (gravity == -1) { gravity = DEFAULT_CHILD_GRAVITY; } int layoutDirection = getResolvedLayoutDirection(); int absoluteGravity = android.view.Gravity.getAbsoluteGravity(gravity, layoutDirection ); int verticalGravity = gravity & android.view.Gravity.VERTICAL_GRAVITY_MASK; switch (absoluteGravity & android.view.Gravity.HORIZONTAL_GRAVITY_MASK) { case android.view.Gravity.LEFT: { childLeft = parentLeft + lp.leftMargin; break; } case android.view.Gravity.CENTER_HORIZONTAL: { childLeft = parentLeft + (parentRight - parentLeft - width) / 2 + lp.leftMargin - lp.rightMargin; break; } case android.view.Gravity.RIGHT: { childLeft = parentRight - width - lp.rightMargin; break; } default: { childLeft = parentLeft + lp.leftMargin; break; } } switch (verticalGravity) { case android.view.Gravity.TOP: { childTop = parentTop + lp.topMargin; break; } case android.view.Gravity.CENTER_VERTICAL: { childTop = parentTop + (parentBottom - parentTop - height) / 2 + lp.topMargin - lp .bottomMargin; break; } case android.view.Gravity.BOTTOM: { childTop = parentBottom - height - lp.bottomMargin; break; } default: { childTop = parentTop + lp.topMargin; break; } } child.layout(childLeft, childTop, childLeft + width, childTop + height); } } } }