Android StaticLayout - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android StaticLayout class.

This code example shows how to use the following methods:draw, getLineCount
	private int getTextLineCount(CharSequence source, TextPaint paint, int widthPx, float textSize) {
		// Update the text paint object 
		paint.setTextSize(textSize);
 
		// Draw using a static layout 
		StaticLayout layout = new StaticLayout(source, paint, widthPx, Alignment.ALIGN_NORMAL, mSpacingMult,
				mSpacingAdd, true);
		layout.draw(TEXT_RESIZE_CANVAS);
 
		return layout.getLineCount();
	} 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getLineBounds, getWidth
This code example shows how to use the following methods:getLineEnd, getLineCount
 
    private void calculateDrawingData() { 
        sDefaultPaint.setTextSize(mCoordinates.subjectFontSize);
        calculateSubjectText(); 
        mSubjectLayout = new StaticLayout(mText, sDefaultPaint,
                mCoordinates.subjectWidth, Alignment.ALIGN_NORMAL, 1, 0, false /* includePad */);
        if (mCoordinates.subjectLineCount < mSubjectLayout.getLineCount()) {
            // TODO: ellipsize. 
            int end = mSubjectLayout.getLineEnd(mCoordinates.subjectLineCount - 1);
            mSubjectLayout = new StaticLayout(mText.subSequence(0, end),
                    sDefaultPaint, mCoordinates.subjectWidth, Alignment.ALIGN_NORMAL, 1, 0, true);
        } 
 
        // Now, format the sender for its width 
        TextPaint senderPaint = mRead ? sDefaultPaint : sBoldPaint;
        // And get the ellipsized string for the calculated width 
        if (TextUtils.isEmpty(mSender)) {
            mFormattedSender = "";
        } else { 
            int senderWidth = mCoordinates.sendersWidth;
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getHeight
 
        // Layout the text. 
        int outerWidth = right - config.mTitleLeft;
        String title = mTitle;
        mTitleLayout = new StaticLayout(title, 0, title.length(), config.mPaint, outerWidth, Layout.Alignment.ALIGN_NORMAL, 1, 0,
                true, TextUtils.TruncateAt.MIDDLE, outerWidth);
        mTitleY = top + (height - mTitleLayout.getHeight()) / 2;
    } 
 
    public static final class Config { 
        private final int mIconLeft;
        private final int mTitleLeft;
        private final int mIconSize;
        private final TextPaint mPaint;
 
        public Config(int iconSpan, int iconSize, TextPaint paint) {
            mIconLeft = (iconSpan - iconSize) / 2;
            mTitleLeft = iconSpan;
            mIconSize = iconSize;
            mPaint = paint;
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:draw, getHeight
	// Set the text size of the text paint object and use a static layout to render text off screen before measuring 
	private int getTextRect(CharSequence source, TextPaint paint, int width, float textSize) {
		// Update the text paint object 
		paint.setTextSize(textSize);
		// Draw using a static layout 
		StaticLayout layout = new StaticLayout(source, paint, width, Alignment.ALIGN_NORMAL, spacingMult, spacingAdd, false);
		layout.draw(textResizeCanvas);
		return layout.getHeight();
	} 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getLineCount
		layout.draw(canvas);
	} 
 
	@Override 
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		Layout layout = new StaticLayout(getText(), mTextPaintOutline, measureWidth(widthMeasureSpec), Layout.Alignment.ALIGN_CENTER, mSpacingMult, mSpacingAdd, mIncludePad);
		int ex = (int) (mBorderSize * 2 + 1);
		setMeasuredDimension(measureWidth(widthMeasureSpec) + ex, measureHeight(heightMeasureSpec) * layout.getLineCount() + ex);
	} 
 
	private int measureWidth(int measureSpec) {
		int result = 0;
		int specMode = MeasureSpec.getMode(measureSpec);
		int specSize = MeasureSpec.getSize(measureSpec);
 
		if (specMode == MeasureSpec.EXACTLY) {
			result = specSize;
		} else { 
			result = (int) mTextPaintOutline.measureText(mText) + getPaddingLeft() + getPaddingRight();
			if (specMode == MeasureSpec.AT_MOST) {
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
            } 
        } 
    } 
 
    private Layout createWorkingLayout(String workingText) {
        return new StaticLayout(workingText, getPaint(), getWidth() - getPaddingLeft() - getPaddingRight(),
                Alignment.ALIGN_NORMAL, lineSpacingMultiplier, lineAdditionalVerticalPadding, false);
    } 
 
    @Override 
    public void setEllipsize(TruncateAt where) {
        // Ellipsize settings are not respected 
    } 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getHeight
    // Set the text size of the text paint object and use a static layout to render text off screen before measuring 
    private int getTextHeight(CharSequence source, TextPaint paint, int width, float textSize) {
        // Update the text paint object 
        paint.setTextSize(textSize);
        // Measure using a static layout 
        StaticLayout layout = new StaticLayout(source, paint, width, Alignment.ALIGN_NORMAL, mSpacingMult, mSpacingAdd, true);
        return layout.getHeight();
    } 
 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getHeight
    else if (alignment == 2) {
      _alignment = Layout.Alignment.ALIGN_OPPOSITE;
    } 
 
    layout = new StaticLayout(text, paint, textWidth,
        _alignment, 1, 0, false);
 
    textHeight = (int)Math.ceil(layout.getHeight());
    if (textHeight > maxHeightPixels) {
      textHeight = maxHeightPixels;
    } 
    else if (textHeight <= 0) {
      textHeight = 1;
    } 
  } 
 
  private void prepare() { 
    paint = new TextPaint();
 
    Typeface typeface = getTypeface();
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:draw, getHeight
6
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android StaticLayout Questions & Answers:

See Code Examples for Android StaticLayout Methods: