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


Java Paint.getTextAlign方法代码示例

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


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

示例1: getDx

import android.graphics.Paint; //导入方法依赖的package包/类
private float getDx(final int width,
                    final int horizontalGravity,
                    final Paint paint,
                    final StaticLayout layout) {
    final boolean centered = paint.getTextAlign() == Paint.Align.CENTER;
    final float dx;
    switch (horizontalGravity) { // No support for GravityCompat.END
        case Gravity.CENTER_HORIZONTAL:
            dx = (width >> 1) - (centered ? 0 : (layout.getWidth() >> 1) - getPaddingLeft());
            break;
        default:
        case GravityCompat.START:
            dx = getPaddingLeft();
            break;
    }
    return dx;
}
 
开发者ID:tylersuehr7,项目名称:empty-state-recyclerview,代码行数:18,代码来源:TextStateDisplay.java

示例2: calcTextBounds

import android.graphics.Paint; //导入方法依赖的package包/类
public Rect calcTextBounds(String text, Paint paint, double dTextSize, double dSpaceBtwTxtLines)	{
    float fPaintOriginalTxtSize = paint.getTextSize();
    Align alignOriginal = paint.getTextAlign();
    Rect rectTxtBox = new Rect(); // rectTxtBox gives original text box and returns the actual text box
    if (text == null)	{
    	return rectTxtBox;	// null protection.
    }
    paint.setTextSize((float)dTextSize);
    paint.setTextAlign(Align.LEFT);
    String[] lines = text.split("\n");
    for (int i = 0; i < lines.length; ++i) {
    	int nTxtWidth = (int)Math.ceil(paint.measureText(lines[i]));
        if (i == 0)    {
            rectTxtBox.left = 0;
            rectTxtBox.right = nTxtWidth;	//rect.right;
            rectTxtBox.top = 0;
            rectTxtBox.bottom = (int)Math.ceil(-paint.ascent() + paint.descent());//rect.height();
        } else    {
            rectTxtBox.right = Math.max(rectTxtBox.right, nTxtWidth);
            rectTxtBox.bottom = (int) (rectTxtBox.bottom + (int)Math.ceil(-paint.ascent() + paint.descent()) + dSpaceBtwTxtLines);
        }
    }
    paint.setTextAlign(alignOriginal);
    paint.setTextSize(fPaintOriginalTxtSize);
    return rectTxtBox;
}
 
开发者ID:woshiwpa,项目名称:SmartMath,代码行数:27,代码来源:OGLChart.java

示例3: drawXAxisValue

import android.graphics.Paint; //导入方法依赖的package包/类
public static void drawXAxisValue(Canvas c, String text, float x, float y,
                                  Paint paint,
                                  MPPointF anchor, float angleDegrees) {

    float drawOffsetX = 0.f;
    float drawOffsetY = 0.f;

    final float lineHeight = paint.getFontMetrics(mFontMetricsBuffer);
    paint.getTextBounds(text, 0, text.length(), mDrawTextRectBuffer);

    // Android sometimes has pre-padding
    drawOffsetX -= mDrawTextRectBuffer.left;

    // Android does not snap the bounds to line boundaries,
    //  and draws from bottom to top.
    // And we want to normalize it.
    drawOffsetY += -mFontMetricsBuffer.ascent;

    // To have a consistent point of reference, we always draw left-aligned
    Paint.Align originalTextAlign = paint.getTextAlign();
    paint.setTextAlign(Paint.Align.LEFT);

    if (angleDegrees != 0.f) {

        // Move the text drawing rect in a way that it always rotates around its center
        drawOffsetX -= mDrawTextRectBuffer.width() * 0.5f;
        drawOffsetY -= lineHeight * 0.5f;

        float translateX = x;
        float translateY = y;

        // Move the "outer" rect relative to the anchor, assuming its centered
        if (anchor.x != 0.5f || anchor.y != 0.5f) {
            final FSize rotatedSize = getSizeOfRotatedRectangleByDegrees(
                    mDrawTextRectBuffer.width(),
                    lineHeight,
                    angleDegrees);

            translateX -= rotatedSize.width * (anchor.x - 0.5f);
            translateY -= rotatedSize.height * (anchor.y - 0.5f);
            FSize.recycleInstance(rotatedSize);
        }

        c.save();
        c.translate(translateX, translateY);
        c.rotate(angleDegrees);

        c.drawText(text, drawOffsetX, drawOffsetY, paint);

        c.restore();
    } else {
        if (anchor.x != 0.f || anchor.y != 0.f) {

            drawOffsetX -= mDrawTextRectBuffer.width() * anchor.x;
            drawOffsetY -= lineHeight * anchor.y;
        }

        drawOffsetX += x;
        drawOffsetY += y;

        c.drawText(text, drawOffsetX, drawOffsetY, paint);
    }

    paint.setTextAlign(originalTextAlign);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:66,代码来源:Utils.java


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