当前位置: 首页>>代码示例>>Java>>正文


Java ApiCompatibilityUtils.getPaddingStart方法代码示例

本文整理汇总了Java中org.chromium.base.ApiCompatibilityUtils.getPaddingStart方法的典型用法代码示例。如果您正苦于以下问题:Java ApiCompatibilityUtils.getPaddingStart方法的具体用法?Java ApiCompatibilityUtils.getPaddingStart怎么用?Java ApiCompatibilityUtils.getPaddingStart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.chromium.base.ApiCompatibilityUtils的用法示例。


在下文中一共展示了ApiCompatibilityUtils.getPaddingStart方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onDraw

import org.chromium.base.ApiCompatibilityUtils; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    boolean isRtl = ApiCompatibilityUtils.isLayoutRtl(this);
    int paddingStart = ApiCompatibilityUtils.getPaddingStart(this);
    int widthWithoutPadding = getWidth() - paddingStart;

    canvas.save();
    if (!isRtl) canvas.translate(paddingStart, 0);

    canvas.save();
    canvas.translate(0, (getHeight() - mNormalDrawable.getIntrinsicHeight()) / 2.f);
    if (isRtl) {
        canvas.translate(widthWithoutPadding - mNormalDrawable.getIntrinsicWidth(), 0);
    }
    mNormalDrawable.draw(canvas);
    canvas.restore();

    if (mIsIncognito || (mTransitionAnimation != null && mTransitionAnimation.isRunning())) {
        canvas.save();
        canvas.translate(0, (getHeight() - mIncognitoDrawable.getIntrinsicHeight()) / 2.f);
        if (isRtl) {
            canvas.translate(widthWithoutPadding - mIncognitoDrawable.getIntrinsicWidth(), 0);
        }
        mIncognitoDrawable.draw(canvas);
        canvas.restore();
    }

    canvas.restore();
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:32,代码来源:NewTabButton.java

示例2: onMeasure

import org.chromium.base.ApiCompatibilityUtils; //导入方法依赖的package包/类
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int totalWidth = resolveSize(mMaxWidth, widthMeasureSpec);
    int childCount = getChildCount();
    if (childCount == 0) {
        setMeasuredDimension(totalWidth, resolveSize(0, heightMeasureSpec));
        return;
    }

    // Measure the children.
    for (int i = 0; i < childCount; i++) {
        measureChild(getChildAt(i), MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
    }

    // Determine the number of columns that will fit.
    int gridWidth = totalWidth - ApiCompatibilityUtils.getPaddingStart(this)
            - ApiCompatibilityUtils.getPaddingEnd(this);
    int childHeight = getChildAt(0).getMeasuredHeight();
    int childWidth = getChildAt(0).getMeasuredWidth();
    int numColumns = MathUtils.clamp(
            (gridWidth + mMinHorizontalSpacing) / (childWidth + mMinHorizontalSpacing),
            1, MAX_COLUMNS);

    // Ensure column spacing isn't greater than mMaxHorizontalSpacing.
    int gridWidthMinusColumns = Math.max(0, gridWidth - numColumns * childWidth);
    int gridSidePadding = gridWidthMinusColumns - mMaxHorizontalSpacing * (numColumns - 1);

    int gridStart = 0;
    float horizontalSpacing;
    if (gridSidePadding > 0) {
        horizontalSpacing = mMaxHorizontalSpacing;
        gridStart = gridSidePadding / 2;
    } else {
        horizontalSpacing = (float) gridWidthMinusColumns / Math.max(1, numColumns - 1);
    }

    // Limit the number of rows to mMaxRows.
    int visibleChildCount = Math.min(childCount, mMaxRows * numColumns);

    // Arrange the visible children in a grid.
    int numRows = (visibleChildCount + numColumns - 1) / numColumns;
    int paddingTop = getPaddingTop();
    boolean isRtl = ApiCompatibilityUtils.isLayoutRtl(this);
    for (int i = 0; i < visibleChildCount; i++) {
        View child = getChildAt(i);
        child.setVisibility(View.VISIBLE);
        int row = i / numColumns;
        int column = i % numColumns;
        int verticalOffset = Math.round(mExtraVerticalSpacing * ((float) (row + 1) / numRows));
        int childTop = row * (childHeight + mVerticalSpacing) + verticalOffset;
        int childStart = gridStart + Math.round(column * (childWidth + horizontalSpacing));
        MarginLayoutParams layoutParams = (MarginLayoutParams) child.getLayoutParams();
        layoutParams.setMargins(isRtl ? 0 : childStart, childTop, isRtl ? childStart : 0, 0);
        child.setLayoutParams(layoutParams);
    }

    // Hide any extra children in case there are more than needed for the maximum number of
    // rows.
    for (int i = visibleChildCount; i < childCount; i++) {
        getChildAt(i).setVisibility(View.GONE);
    }

    int totalHeight = paddingTop + getPaddingBottom() + numRows * childHeight
            + (numRows - 1) * mVerticalSpacing + mExtraVerticalSpacing;

    setMeasuredDimension(totalWidth, resolveSize(totalHeight, heightMeasureSpec));
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:68,代码来源:MostVisitedLayout.java


注:本文中的org.chromium.base.ApiCompatibilityUtils.getPaddingStart方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。