android.text.Layout.getSpacingAdd()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(3.3k)|赞(0)|评价(0)|浏览(213)

本文整理了Java中android.text.Layout.getSpacingAdd()方法的一些代码示例,展示了Layout.getSpacingAdd()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Layout.getSpacingAdd()方法的具体详情如下:
包路径:android.text.Layout
类名称:Layout
方法名:getSpacingAdd

Layout.getSpacingAdd介绍

暂无

代码示例

代码示例来源:origin: facebook/TextLayoutBuilder

/**
 * Prior to version 20, If the Layout specifies extra space between lines (either by spacingmult
 * or spacingadd) the StaticLayout would erroneously add this space after the last line as well.
 * This bug was fixed in version 20. This method calculates the extra space and reduces the height
 * by that amount.
 *
 * @param layout The layout.
 * @return The height of the layout.
 */
public static int getHeight(Layout layout) {
 if (layout == null) {
  return 0;
 }
 int extra = 0;
 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT_WATCH
   && layout instanceof StaticLayout) {
  int line = Math.max(0, layout.getLineCount() - 1);
  int above = layout.getLineAscent(line);
  int below = layout.getLineDescent(line);
  float originalSize = (below - above - layout.getSpacingAdd()) / layout.getSpacingMultiplier();
  float ex = below - above - originalSize;
  if (ex >= 0) {
   extra = (int) (ex + 0.5);
  } else {
   extra = -(int) (-ex + 0.5);
  }
 }
 return layout.getHeight() - extra;
}

代码示例来源:origin: facebook/TextLayoutBuilder

@Test
public void testSetTextSpacingExtra() {
 mLayout = mBuilder.setTextSpacingExtra(10).build();
 assertEquals(mBuilder.getTextSpacingExtra(), 10.0f, 0.0f);
 assertEquals(mLayout.getSpacingAdd(), 10.0f, 0.0f);
}

代码示例来源:origin: facebook/TextLayoutBuilder

@Test
public void testSetTextLineHeight() {
 final float lineHeight = 15f;
 mLayout = mBuilder.setLineHeight(lineHeight).build();
 assertEquals(mBuilder.getLineHeight(), 15f, 0.0f);
 assertEquals(mLayout.getSpacingMultiplier(), 1.0f, 0.0f);
 assertEquals(
   mLayout.getSpacingAdd(), lineHeight - mLayout.getPaint().getFontMetrics(null), 0.0f);
}

代码示例来源:origin: stackoverflow.com

final Layout originalLayout = super.getLayout();
 final Layout layout = new StaticLayout(text, mStrokePaint,
 originalLayout.getWidth(), originalLayout.getAlignment(),
 originalLayout.getSpacingMultiplier(), originalLayout.getSpacingAdd(), true);
 canvas.save();
 canvas.translate( layout.getLineWidth(0) * 0.5f, 0.0f );
 layout.draw(canvas);
 canvas.restore();

代码示例来源:origin: smuyyh/SprintNBA

textHeight = textHeight * layout.getSpacingMultiplier() + layout.getSpacingAdd();

代码示例来源:origin: fanatic-mobile-developer-for-android/A-week-to-develop-android-app-plan

textHeight = (int) (textHeight * layout.getSpacingMultiplier() + layout.getSpacingAdd());

代码示例来源:origin: anitaa1990/TrailersApp

@Override
protected void onDraw(Canvas canvas) {
  TextPaint paint = getPaint();
  paint.setColor(getCurrentTextColor());
  paint.drawableState = getDrawableState();
  mViewWidth = getMeasuredWidth();
  String text = getText().toString();
  mLineY = 0;
  mLineY += getTextSize();
  Layout layout = getLayout();
  // layout.getLayout()在4.4.3出现NullPointerException
  if (layout == null) {
    return;
  }
  Paint.FontMetrics fm = paint.getFontMetrics();
  int textHeight = (int) (Math.ceil(fm.descent - fm.ascent));
  textHeight = (int) (textHeight * layout.getSpacingMultiplier() + layout.getSpacingAdd());
  for (int i = 0; i < layout.getLineCount(); i++) {
    int lineStart = layout.getLineStart(i);
    int lineEnd = layout.getLineEnd(i);
    float width = StaticLayout.getDesiredWidth(text, lineStart, lineEnd, getPaint());
    String line = text.substring(lineStart, lineEnd);
    if (needScale(line) && i < layout.getLineCount() -1) {
      drawScaledText(canvas, lineStart, line, width);
    } else {
      canvas.drawText(line, 0, mLineY, paint);
    }
    mLineY += textHeight;
  }
}

相关文章