當前位置: 首頁>>代碼示例>>Java>>正文


Java View.getBaseline方法代碼示例

本文整理匯總了Java中android.view.View.getBaseline方法的典型用法代碼示例。如果您正苦於以下問題:Java View.getBaseline方法的具體用法?Java View.getBaseline怎麽用?Java View.getBaseline使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.view.View的用法示例。


在下文中一共展示了View.getBaseline方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getBaseline

import android.view.View; //導入方法依賴的package包/類
@Override
public int getBaseline() {
    View child = null;

    if (getChildCount() > 0) {
        child = getChildAt(0);
    } else if (mAdapter != null && mAdapter.getCount() > 0) {
        child = makeAndAddView(0);
        mRecycler.put(0, child);
        removeAllViewsInLayout();
    }

    if (child != null) {
        final int childBaseline = child.getBaseline();
        return childBaseline >= 0 ? child.getTop() + childBaseline : -1;
    } else {
        return -1;
    }
}
 
開發者ID:treasure-lau,項目名稱:CSipSimple,代碼行數:20,代碼來源:IcsSpinner.java

示例2: onMeasure

import android.view.View; //導入方法依賴的package包/類
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int count = getChildCount();
    int maxWidth = 0;
    int maxHeight = 0;
    int maxChildBaseline = -1;
    int maxChildDescent = -1;
    int childState = 0;

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

        measureChild(child, widthMeasureSpec, heightMeasureSpec);
        final int baseline = child.getBaseline();
        if (baseline != -1) {
            maxChildBaseline = Math.max(maxChildBaseline, baseline);
            maxChildDescent = Math.max(maxChildDescent, child.getMeasuredHeight() - baseline);
        }
        maxWidth = Math.max(maxWidth, child.getMeasuredWidth());
        maxHeight = Math.max(maxHeight, child.getMeasuredHeight());
        childState = ViewUtils.combineMeasuredStates(childState,
                ViewCompat.getMeasuredState(child));
    }
    if (maxChildBaseline != -1) {
        maxHeight = Math.max(maxHeight, maxChildBaseline + maxChildDescent);
        mBaseline = maxChildBaseline;
    }
    maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight());
    maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
    setMeasuredDimension(
            ViewCompat.resolveSizeAndState(maxWidth, widthMeasureSpec, childState),
            ViewCompat.resolveSizeAndState(maxHeight, heightMeasureSpec,
                    childState << MEASURED_HEIGHT_STATE_SHIFT));
}
 
開發者ID:Trumeet,項目名稱:MiPushFramework,代碼行數:37,代碼來源:BaselineLayout.java

示例3: onLayout

import android.view.View; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:Trumeet,項目名稱:MiPushFramework,代碼行數:29,代碼來源:BaselineLayout.java

示例4: getBaseline

import android.view.View; //導入方法依賴的package包/類
public int getBaseline() {
    if (this.mBaselineAlignedChildIndex < 0) {
        return super.getBaseline();
    }
    if (getChildCount() <= this.mBaselineAlignedChildIndex) {
        throw new RuntimeException("mBaselineAlignedChildIndex of LinearLayout set to an index that is out of bounds.");
    }
    View child = getChildAt(this.mBaselineAlignedChildIndex);
    int childBaseline = child.getBaseline();
    if (childBaseline != -1) {
        int childTop = this.mBaselineChildTop;
        if (this.mOrientation == 1) {
            int majorGravity = this.mGravity & 112;
            if (majorGravity != 48) {
                switch (majorGravity) {
                    case 16:
                        childTop += ((((getBottom() - getTop()) - getPaddingTop()) - getPaddingBottom()) - this.mTotalLength) / 2;
                        break;
                    case 80:
                        childTop = ((getBottom() - getTop()) - getPaddingBottom()) - this.mTotalLength;
                        break;
                }
            }
        }
        return (((LayoutParams) child.getLayoutParams()).topMargin + childTop) + childBaseline;
    } else if (this.mBaselineAlignedChildIndex == 0) {
        return -1;
    } else {
        throw new RuntimeException("mBaselineAlignedChildIndex of LinearLayout points to a View that doesn't know how to get its baseline.");
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:32,代碼來源:LinearLayoutCompat.java

示例5: layoutSingleChildHorizontal

import android.view.View; //導入方法依賴的package包/類
/**
 * Place a single View when the layout direction is horizontal ({@link #mFlexDirection} is
 * either {@link #FLEX_DIRECTION_ROW} or {@link #FLEX_DIRECTION_ROW_REVERSE}).
 *
 * @param view       the View to be placed
 * @param flexLine   the {@link FlexLine} where the View belongs to
 * @param flexWrap   the flex wrap attribute of this FlexboxLayout
 * @param alignItems the align items attribute of this FlexboxLayout
 * @param left       the left position of the View, which the View's margin is already taken
 *                   into account
 * @param top        the top position of the flex line where the View belongs to. The actual
 *                   View's top position is shifted depending on the flexWrap and alignItems
 *                   attributes
 * @param right      the right position of the View, which the View's margin is already taken
 *                   into account
 * @param bottom     the bottom position of the flex line where the View belongs to. The actual
 *                   View's bottom position is shifted depending on the flexWrap and alignItems
 *                   attributes
 * @see #getAlignItems()
 * @see #setAlignItems(int)
 * @see LayoutParams#alignSelf
 */
private void layoutSingleChildHorizontal(View view, FlexLine flexLine, @FlexWrap int flexWrap,
        int alignItems, int left, int top, int right, int bottom) {
    LayoutParams lp = (LayoutParams) view.getLayoutParams();
    if (lp.alignSelf != LayoutParams.ALIGN_SELF_AUTO) {
        // Expecting the values for alignItems and alignSelf match except for ALIGN_SELF_AUTO.
        // Assigning the alignSelf value as alignItems should work.
        alignItems = lp.alignSelf;
    }
    int crossSize = flexLine.mCrossSize;
    switch (alignItems) {
        case ALIGN_ITEMS_FLEX_START: // Intentional fall through
        case ALIGN_ITEMS_STRETCH:
            if (flexWrap != FLEX_WRAP_WRAP_REVERSE) {
                view.layout(left, top + lp.topMargin, right, bottom + lp.topMargin);
            } else {
                view.layout(left, top - lp.bottomMargin, right, bottom - lp.bottomMargin);
            }
            break;
        case ALIGN_ITEMS_BASELINE:
            if (flexWrap != FLEX_WRAP_WRAP_REVERSE) {
                int marginTop = flexLine.mMaxBaseline - view.getBaseline();
                marginTop = Math.max(marginTop, lp.topMargin);
                view.layout(left, top + marginTop, right, bottom + marginTop);
            } else {
                int marginBottom = flexLine.mMaxBaseline - view.getMeasuredHeight() + view
                        .getBaseline();
                marginBottom = Math.max(marginBottom, lp.bottomMargin);
                view.layout(left, top - marginBottom, right, bottom - marginBottom);
            }
            break;
        case ALIGN_ITEMS_FLEX_END:
            if (flexWrap != FLEX_WRAP_WRAP_REVERSE) {
                view.layout(left,
                        top + crossSize - view.getMeasuredHeight() - lp.bottomMargin,
                        right, top + crossSize - lp.bottomMargin);
            } else {
                // If the flexWrap == FLEX_WRAP_WRAP_REVERSE, the direction of the
                // flexEnd is flipped (from top to bottom).
                view.layout(left, top - crossSize + view.getMeasuredHeight() + lp.topMargin,
                        right, bottom - crossSize + view.getMeasuredHeight() + lp.topMargin);
            }
            break;
        case ALIGN_ITEMS_CENTER:
            int topFromCrossAxis = (crossSize - view.getMeasuredHeight()
                    + lp.topMargin - lp.bottomMargin) / 2;
            if (flexWrap != FLEX_WRAP_WRAP_REVERSE) {
                view.layout(left, top + topFromCrossAxis,
                        right, top + topFromCrossAxis + view.getMeasuredHeight());
            } else {
                view.layout(left, top - topFromCrossAxis,
                        right, top - topFromCrossAxis + view.getMeasuredHeight());
            }
            break;
    }
}
 
開發者ID:liu-xiao-dong,項目名稱:JD-Test,代碼行數:78,代碼來源:FlexboxLayout.java


注:本文中的android.view.View.getBaseline方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。