本文整理汇总了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;
}
}
示例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));
}
示例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);
}
}
示例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.");
}
}
示例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;
}
}