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


Java StaticLayout类代码示例

本文整理汇总了Java中android.text.StaticLayout的典型用法代码示例。如果您正苦于以下问题:Java StaticLayout类的具体用法?Java StaticLayout怎么用?Java StaticLayout使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: createUnrestrictedLayout

import android.text.StaticLayout; //导入依赖的package包/类
private static Layout createUnrestrictedLayout(@Nonnull TextView view) {
    CharSequence text = view.getText();
    Layout layout = view.getLayout();
    TextPaint paint = layout.getPaint();

    if (SDK_INT >= M) {
        return StaticLayout.Builder
                .obtain(text, 0, text.length(), layout.getPaint(), layout.getWidth())
                .setAlignment(layout.getAlignment())
                .setLineSpacing(view.getLineSpacingExtra(), view.getLineSpacingMultiplier())
                .setIncludePad(view.getIncludeFontPadding())
                .setBreakStrategy(view.getBreakStrategy())
                .setHyphenationFrequency(view.getHyphenationFrequency())
                .build();
    } else {
        return new StaticLayout(
                text,
                paint,
                text.length(),
                layout.getAlignment(),
                view.getLineSpacingMultiplier(),
                view.getLineSpacingExtra(),
                view.getIncludeFontPadding());
    }
}
 
开发者ID:shazam,项目名称:reflow-animator,代码行数:26,代码来源:ReflowTextAnimatorHelper.java

示例2: drawCenterMultiText1

import android.text.StaticLayout; //导入依赖的package包/类
/**
 * 绘制多行居中文本(方式1)
 *
 * @param canvas 画布
 */
private void drawCenterMultiText1(Canvas canvas) {
    String text = "ABC";

    // 画笔
    TextPaint textPaint = new TextPaint();
    textPaint.setAntiAlias(true);
    textPaint.setColor(Color.GRAY);

    // 设置宽度超过50dp时换行
    StaticLayout staticLayout = new StaticLayout(text, textPaint, dp2px(50),
            Layout.Alignment.ALIGN_CENTER, 1, 0, false);
    canvas.save();
    // StaticLayout默认从(0,0)点开始绘制
    // 如果需要调整位置,只能在绘制之前移动Canvas的起始坐标
    canvas.translate(-staticLayout.getWidth() / 2, -staticLayout.getHeight() / 2);
    staticLayout.draw(canvas);
    canvas.restore();
}
 
开发者ID:alidili,项目名称:Demos,代码行数:24,代码来源:CustomTextView.java

示例3: adjustBottomLines

import android.text.StaticLayout; //导入依赖的package包/类
/**
 * @return True, if adjustments were made that require the view to be invalidated.
 */
private boolean adjustBottomLines() {
  // Bail out if we have a zero width; lines will be adjusted during next layout.
  if (getWidth() == 0) {
    return false;
  }
  int destBottomLines;
  textPaint.setTextSize(bottomTextSize);
  if (tempErrorText != null || helperText != null) {
    Layout.Alignment alignment = (getGravity() & Gravity.RIGHT) == Gravity.RIGHT || isRTL() ?
      Layout.Alignment.ALIGN_OPPOSITE : (getGravity() & Gravity.LEFT) == Gravity.LEFT ?
      Layout.Alignment.ALIGN_NORMAL : Layout.Alignment.ALIGN_CENTER;
    textLayout = new StaticLayout(tempErrorText != null ? tempErrorText : helperText, textPaint, getWidth() - getBottomTextLeftOffset() - getBottomTextRightOffset() - getPaddingLeft() - getPaddingRight(), alignment, 1.0f, 0.0f, true);
    destBottomLines = Math.max(textLayout.getLineCount(), minBottomTextLines);
  } else {
    destBottomLines = minBottomLines;
  }
  if (bottomLines != destBottomLines) {
    getBottomLinesAnimator(destBottomLines).start();
  }
  bottomLines = destBottomLines;
  return true;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:MaterialAutoCompleteTextView.java

示例4: adjustBottomLines

import android.text.StaticLayout; //导入依赖的package包/类
/**
 * @return True, if adjustments were made that require the view to be invalidated.
 */
private boolean adjustBottomLines() {
  // Bail out if we have a zero width; lines will be adjusted during next layout.
  if (getWidth() == 0) {
    return false;
  }
  int destBottomLines;
  textPaint.setTextSize(bottomTextSize);
  if (tempErrorText != null || helperText != null) {
    Layout.Alignment alignment = (getGravity() & Gravity.RIGHT) == Gravity.RIGHT || isRTL() ?
        Layout.Alignment.ALIGN_OPPOSITE : (getGravity() & Gravity.LEFT) == Gravity.LEFT ?
        Layout.Alignment.ALIGN_NORMAL : Layout.Alignment.ALIGN_CENTER;
    textLayout = new StaticLayout(tempErrorText != null ? tempErrorText : helperText, textPaint, getWidth() - getBottomTextLeftOffset() - getBottomTextRightOffset() - getPaddingLeft() - getPaddingRight(), alignment, 1.0f, 0.0f, true);
    destBottomLines = Math.max(textLayout.getLineCount(), minBottomTextLines);
  } else {
    destBottomLines = minBottomLines;
  }
  if (bottomLines != destBottomLines) {
    getBottomLinesAnimator(destBottomLines).start();
  }
  bottomLines = destBottomLines;
  return true;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:MaterialEditText.java

示例5: measure

import android.text.StaticLayout; //导入依赖的package包/类
private void measure() {
        TextPaint tp = new TextPaint();
        tp.setAntiAlias(true);
        tp.setColor(mTextColor);
        tp.setTextSize(mTextSize);
        strokePaint.setTextSize(mTextSize);
//        tp.setShadowLayer(4, 0, 0, Color.BLACK);
        mContentHeight = getFontHeight(tp);
        staticLayout = new StaticLayout(mContent,
                            tp,
                            (int) Layout.getDesiredWidth(mContent, 0, mContent.length(), tp) + 1,
                            Layout.Alignment.ALIGN_NORMAL,
                            1.0f,
                            0.0f,
                            false);
        mContentWidth = staticLayout.getWidth();
        borderStaticLayout = new StaticLayout(mContent,
                strokePaint,
                (int) Layout.getDesiredWidth(mContent, 0, mContent.length(), tp) + 1,
                Layout.Alignment.ALIGN_NORMAL,
                1.0f,
                0.0f,
                false);
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:DanmakuItem.java

示例6: getDx

import android.text.StaticLayout; //导入依赖的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

示例7: configureTextLayouts

import android.text.StaticLayout; //导入依赖的package包/类
private void configureTextLayouts(final int availableWidth) {
    if (!textLayoutsConfigured) {
        final int totalNeededPadding = getPaddingLeft() + getPaddingRight();

        // Create new static layout only if needed!
        if ((titleLayout.getWidth() + totalNeededPadding) > availableWidth) {
            this.titleLayout = new StaticLayout(title,
                    titlePaint,
                    availableWidth,
                    Layout.Alignment.ALIGN_NORMAL,
                    1.15f, 0, false);
        }

        // Create new static layout only if needed!
        if ((subtitleLayout.getWidth() + totalNeededPadding) > availableWidth) {
            this.subtitleLayout = new StaticLayout(subtitle,
                    subtitlePaint,
                    availableWidth,
                    Layout.Alignment.ALIGN_NORMAL,
                    1.15f, 0, false);
        }

        textLayoutsConfigured = true;
    }
}
 
开发者ID:tylersuehr7,项目名称:empty-state-recyclerview,代码行数:26,代码来源:TextStateDisplay.java

示例8: updateSecretTimeText

import android.text.StaticLayout; //导入依赖的package包/类
private void updateSecretTimeText() {
    if (currentMessageObject == null) {
        return;
    }
    String str = currentMessageObject.getSecretTimeString();
    if (str == null) {
        return;
    }
    if (currentInfoString == null || !currentInfoString.equals(str)) {
        currentInfoString = str;
        infoWidth = (int)Math.ceil(infoPaint.measureText(currentInfoString));
        CharSequence str2 = TextUtils.ellipsize(currentInfoString, infoPaint, infoWidth, TextUtils.TruncateAt.END);
        infoLayout = new StaticLayout(str2, infoPaint, infoWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
        invalidate();
    }
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:17,代码来源:SecretPhotoViewer.java

示例9: checkUnreadCounter

import android.text.StaticLayout; //导入依赖的package包/类
public void checkUnreadCounter(int mask) {
    if (mask != 0 && (mask & MessagesController.UPDATE_MASK_READ_DIALOG_MESSAGE) == 0 && (mask & MessagesController.UPDATE_MASK_NEW_MESSAGE) == 0) {
        return;
    }
    TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs_dict.get(dialog_id);
    if (dialog != null && dialog.unread_count != 0) {
        if (lastUnreadCount != dialog.unread_count) {
            lastUnreadCount = dialog.unread_count;
            String countString = String.format("%d", dialog.unread_count);
            countWidth = Math.max(AndroidUtilities.dp(12), (int) Math.ceil(countPaint.measureText(countString)));
            countLayout = new StaticLayout(countString, countPaint, countWidth, Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);
            if (mask != 0) {
                invalidate();
            }
        }
    } else if (countLayout != null) {
        if (mask != 0) {
            invalidate();
        }
        lastUnreadCount = 0;
        countLayout = null;
    }
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:24,代码来源:HintDialogCell.java

示例10: setTitle

import android.text.StaticLayout; //导入依赖的package包/类
public void setTitle(String title) {
    stringBuilder.setLength(0);
    if (title != null && title.length() > 0) {
        stringBuilder.append(title.substring(0, 1));
    }

    if (stringBuilder.length() > 0) {
        String text = stringBuilder.toString().toUpperCase();
        try {
            textLayout = new StaticLayout(text, namePaint, AndroidUtilities.dp(100), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
            if (textLayout.getLineCount() > 0) {
                textLeft = textLayout.getLineLeft(0);
                textWidth = textLayout.getLineWidth(0);
                textHeight = textLayout.getLineBottom(0);
            }
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
    } else {
        textLayout = null;
    }
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:23,代码来源:LetterDrawable.java

示例11: init

import android.text.StaticLayout; //导入依赖的package包/类
private void init() {
    circlePaint = new Paint();
    circlePaint.setAntiAlias(true);
    circlePaint.setDither(true);
    circlePaint.setColor(backgroundColor);
    circlePaint.setStyle(Paint.Style.FILL);

    textPaint = new TextPaint();
    textPaint.setAntiAlias(true);
    textPaint.setDither(true);
    textPaint.setColor(textColor);
    textPaint.setTextSize(textSize);
    textPaint.setTextAlign(Paint.Align.CENTER);

    borderPaint = new Paint();
    borderPaint.setAntiAlias(true);
    borderPaint.setDither(true);
    borderPaint.setColor(borderColor);
    borderPaint.setStrokeWidth(borderWidth);
    borderPaint.setStyle(Paint.Style.STROKE);

    int textWidth = (int) textPaint.measureText(text.substring(0, (text.length() + 1) / 2));
    staticLayout = new StaticLayout(text, textPaint, textWidth, Layout.Alignment.ALIGN_NORMAL, 1F, 0, false);
}
 
开发者ID:ruiqiao2017,项目名称:Renrentou,代码行数:25,代码来源:CountDownView.java

示例12: resetting

import android.text.StaticLayout; //导入依赖的package包/类
private void resetting(){
        float size;
        //字体随滑动变化
        if (level == 5000) {
            size = textSize * 1.1f;
        }else if(level == 10000 || level == 0){
            size = textSize * 1f;
        }else{
            float value = (level / 5000f) - 1f;
            size = textSize + textSize * (1 - Math.abs(value))* 0.1f;
        }

        mTextPaint.setTextSize(size);
        mTextPaint.setColor(defaultTabTextColor);
        int num = (getMeasuredWidth() - indicatorPadding) / (int) size; // 一行可以放下的字数,默认放置两行文字

//        mStaticLayout = new StaticLayout(text, mTextPaint, getMeasuredWidth() - indicatorPadding, Layout.Alignment.ALIGN_NORMAL, 1.0F, 0.0F, false);
        mStaticLayout = new StaticLayout(text, 0, text.length() > num * 2 ?  num * 2 : text.length(), mTextPaint, getMeasuredWidth() - indicatorPadding,
                Layout.Alignment.ALIGN_NORMAL, 1.0F, 0.0F, false);

    }
 
开发者ID:simplezhli,项目名称:ChangeTabLayout,代码行数:22,代码来源:ChangeTextView.java

示例13: makeSingleLayout

import android.text.StaticLayout; //导入依赖的package包/类
private Layout makeSingleLayout(int i, BoringLayout.Metrics metrics, int i2, Alignment alignment, boolean z, TextUtils.TruncateAt truncateAt, boolean z2) {
    BoringLayout.Metrics isBoring;
    if (metrics == UNKNOWN_BORING) {
        isBoring = BoringLayout.isBoring(this.mText, this.mPaint, this.mBoring);
        if (isBoring != null) {
            this.mBoring = isBoring;
        }
    } else {
        isBoring = metrics;
    }
    if (isBoring != null) {
        if (isBoring.width <= i && (truncateAt == null || isBoring.width <= i2)) {
            return BoringLayout.make(this.mText, this.mPaint, i, alignment, this.mLineSpacingMult, this.mLineSpacingAdd, isBoring, this.mIncludeFontPadding);
        } else if (z && isBoring.width <= i) {
            return BoringLayout.make(this.mText, this.mPaint, i, alignment, this.mLineSpacingMult, this.mLineSpacingAdd, isBoring, this.mIncludeFontPadding, truncateAt, i2);
        } else if (z) {
            return StaticLayoutWithMaxLines.create(this.mText, 0, this.mText.length(), this.mPaint, i, alignment, this.mLineSpacingMult, this.mLineSpacingAdd, this.mIncludeFontPadding, truncateAt, i2, this.mMaxLines);
        } else {
            return new StaticLayout(this.mText, this.mPaint, i, alignment, this.mLineSpacingMult, this.mLineSpacingAdd, this.mIncludeFontPadding);
        }
    } else if (z) {
        return StaticLayoutWithMaxLines.create(this.mText, 0, this.mText.length(), this.mPaint, i, alignment, this.mLineSpacingMult, this.mLineSpacingAdd, this.mIncludeFontPadding, truncateAt, i2, this.mMaxLines);
    } else {
        return new StaticLayout(this.mText, this.mPaint, i, alignment, this.mLineSpacingMult, this.mLineSpacingAdd, this.mIncludeFontPadding);
    }
}
 
开发者ID:xieyangxuejun,项目名称:CommentView,代码行数:27,代码来源:CanvasTextArea.java

示例14: getTextHeightPixels

import android.text.StaticLayout; //导入依赖的package包/类
/**
 * Sets the text size of a clone of the view's {@link TextPaint} object
 * and uses a {@link StaticLayout} instance to measure the height of the text.
 *
 * @param source
 * @param availableWidthPixels
 * @param textSizePixels
 * @return the height of the text when placed in a view
 * with the specified width
 * and when the text has the specified size.
 */
private int getTextHeightPixels(
        CharSequence source,
        int availableWidthPixels,
        float textSizePixels) {
    // Make a copy of the original TextPaint object
    // since the object gets modified while measuring
    // (see also the docs for TextView.getPaint()
    // which states to access it read-only)
    TextPaint textPaintCopy = new TextPaint(getPaint());
    textPaintCopy.setTextSize(textSizePixels);
    // Measure using a StaticLayout instance
    StaticLayout staticLayout = new StaticLayout(
            source,
            textPaintCopy,
            availableWidthPixels,
            Layout.Alignment.ALIGN_NORMAL,
            mLineSpacingMultiplier,
            mLineSpacingExtra,
            true);
    return staticLayout.getHeight();
}
 
开发者ID:sega4revenge,项目名称:Sega,代码行数:33,代码来源:AutoResizeTextView.java

示例15: drawText

import android.text.StaticLayout; //导入依赖的package包/类
/**
     * 绘制文字
     *
     * @param canvas 画布
     */
    private void drawText(Canvas canvas, String textString) {
        textRect.left = getPaddingLeft();
        textRect.top = getPaddingTop();
        textRect.right = getWidth() - getPaddingRight();
        textRect.bottom = getHeight() - getPaddingBottom();


        TextPaint textPaint = new TextPaint();
//        textPaint.setARGB(0xFF, 0xFF, 0, 0);
        textPaint.setTextSize(50.0F);
        textPaint.setAntiAlias(true);
/** * aboutTheGame :要 绘制 的 字符串 ,textPaint(TextPaint 类型)设置了字符串格式及属性 的画笔,getWidth()为设置 画多宽后 换行,后面的参数是对齐方式... */
        StaticLayout layout = new StaticLayout(textString,textPaint,getWidth(), Layout.Alignment.ALIGN_NORMAL,1.0F,0.0F,true);
        canvas.save();
        canvas.translate(10,10);
        layout.draw(canvas);
        canvas.restore();//别忘了restore

    }
 
开发者ID:yzzslow0,项目名称:Ec2m,代码行数:25,代码来源:FadeInText.java


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