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

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

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

Layout.getLineDescent介绍

暂无

代码示例

代码示例来源: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: stackoverflow.com

if (mNegativeLineSpacing) { // If you are only supporting Api Level 16 and up, you could use the getLineSpacingExtra() and getLineSpacingMultiplier() methods here to check for a less than 1 spacing instead.
  Layout layout = getLayout();
  int truncatedHeight = layout.getLineDescent(layout.getLineCount()-1);
  setMeasuredDimension(getMeasuredWidth(), getMeasuredHeight() + truncatedHeight);

代码示例来源:origin: Calsign/APDE

protected void display(Canvas canvas, TextPaint customPaint) {
    float lineHeight = getLineHeight();
    float lineOffset = -getLayout().getLineDescent(0); //AH-HA! This is the metric that we need...
    float xOffset = getCompoundPaddingLeft(); //TODO hopefully no one uses Arabic (right-aligned localities)... because getCompoundPaddingStart() was introduced in a later API level
    float charWidth = getPaint().measureText("m");
    
    //Calculate coordinates
    float x = (xOffset + offset * charWidth);
    float y = lineOffset + lineHeight * (lineNum + 1);
    
    //Draw highlighted text
    canvas.drawText(text, x, y, customPaint);
  }
}

代码示例来源:origin: Calsign/APDE

protected void display(Canvas canvas) {
  if (paint == null) { // TODO this is SERIOUSLY fishy
    return;
  }
  
  float lineHeight = getLineHeight();
  float lineOffset = -getLayout().getLineDescent(0); //AH-HA! This is the metric that we need...
  float xOffset = getCompoundPaddingLeft(); //TODO hopefully no one uses Arabic (right-aligned localities)... because getCompoundPaddingStart() was introduced in a later API level
  float charWidth = getPaint().measureText("m");
  
  //Calculate coordinates
  float x = (xOffset + offset * charWidth);
  float y = lineOffset + lineHeight * (lineNum + 1);
  
  //Draw highlighted text
  canvas.drawText(text, x, y, paint);
}

相关文章