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

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

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

Layout.getLineEnd介绍

暂无

代码示例

代码示例来源:origin: hanks-zyh/HTextView

@Override
  protected void drawFrame(Canvas canvas) {
    Layout layout = mHTextView.getLayout();
    int gapIndex = 0;
    for (int i = 0; i < layout.getLineCount(); i++) {
      int lineStart = layout.getLineStart(i);
      int lineEnd = layout.getLineEnd(i);
      float lineLeft = layout.getLineLeft(i);
      float lineBaseline = layout.getLineBaseline(i);
      String lineText = mText.subSequence(lineStart, lineEnd).toString();
      for (int c = 0; c < lineText.length(); c++) {
        int alpha = alphaList.get(gapIndex);
        mPaint.setAlpha((int) ((255 - alpha) * progress + alpha));
        canvas.drawText(String.valueOf(lineText.charAt(c)), lineLeft, lineBaseline, mPaint);
        lineLeft += gapList.get(gapIndex++);
      }
    }
  }
}

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

Layout layout = createWorkingLayout(workingText);
if (layout.getLineCount() > maxLines) {
  workingText = fullText.substring(0, layout.getLineEnd(maxLines - 1)).trim();
  while (createWorkingLayout(workingText + ELLIPSIS).getLineCount() > maxLines) {
    int lastSpace = workingText.lastIndexOf(' ');

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

Layout layout = textView.getLayout();
String text = textView.getText().toString();
int start=0;
int end;
for (int i=0; i<textView.getLineCount(); i++) {
  end = layout.getLineEnd(i);
  line[i] = text.substring(start,end);
  start = end;
}

代码示例来源:origin: seven332/EhViewer

int last = layout.getLineEnd(linebot);

代码示例来源:origin: weexteam/weex-hackernews

int lastLineStart, lastLineEnd;
lastLineStart = layout.getLineStart(mNumberOfLines - 1);
lastLineEnd = layout.getLineEnd(mNumberOfLines - 1);
if (lastLineStart < lastLineEnd) {
 String text = mText.subSequence(0, lastLineStart).toString() +

代码示例来源:origin: FolioReader/FolioReader-Android

@Override
  protected void onDraw(Canvas canvas) {
    int count = getLineCount();

    final Layout layout = getLayout();
    float xStart, xStop, xDiff;
    int firstCharInLine, lastCharInLine;

    for (int i = 0; i < count; i++) {
      int baseline = getLineBounds(i, mRect);
      firstCharInLine = layout.getLineStart(i);
      lastCharInLine = layout.getLineEnd(i);

      xStart = layout.getPrimaryHorizontal(firstCharInLine);
      xDiff = layout.getPrimaryHorizontal(firstCharInLine + 1) - xStart;
      xStop = layout.getPrimaryHorizontal(lastCharInLine - 1) + xDiff;

      canvas.drawLine(xStart,
          baseline + mStrokeWidth,
          xStop,
          baseline + mStrokeWidth,
          mPaint);
    }

    super.onDraw(canvas);
  }
}

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

int lineEnd = layout.getLineEnd(line);
int lineLength = lineEnd - lineStart;
if (lineLength == 0) {

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

holder.timeLineContents.setOnLayoutListener(new OnLayoutListener() {
       @Override
       public void onLayoutChanged(SpanTextView view) {
         SpannableString mLinkableText = null;  
         InternalMoreSpan span = new InternalMoreSpan(mContext);     
         if(view.getLineCount() >= 2) {
           Layout layout = view.getLayout();
           String splitedText = view.getText().toString().substring(0, layout.getLineEnd(2 - 1)  - 6).trim();
           splitedText = splitedText + moreStr;
           mLinkableText = new SpannableString(splitedText);  
           mLinkableText.setSpan(span, mLinkableText.length()- moreStr.length(), mLinkableText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
           view.setText(mLinkableText);
         }
       }
     });

代码示例来源:origin: nspduanlei/Reader

/**
 * 获取当前页总字数
 */
public int getCharNum() {
  return getLayout().getLineEnd(getLineNum());
}

代码示例来源:origin: lovejjfg/PowerText

private int getMoreLength(Layout layout, int moreLength, CharSequence mText) {
  int lastLine = mDefaultLineCount - 1;
  moreLength++;
  CharSequence newText =
    mText.subSequence(layout.getLineStart(lastLine), layout.getLineEnd(lastLine) - moreLength);
  while (getPaint().measureText(newText + "..." + mMoreHint) > layout.getWidth()) {
    moreLength++;
    newText = mText.subSequence(layout.getLineStart(lastLine), layout.getLineEnd(lastLine) - moreLength);
  }
  return moreLength;
}

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

public static List<CharSequence> getLines(TextView view) {
  final List<CharSequence> lines = new ArrayList<>();
  final Layout layout = view.getLayout();

  if (layout != null) {
    final int lineCount = layout.getLineCount();
    final CharSequence text = layout.getText();

    for (int i = 0, startIndex = 0; i < lineCount; i++) {
      final int endIndex = layout.getLineEnd(i);
      lines.add(text.subSequence(startIndex, endIndex));
      startIndex = endIndex;
    }
  }
  return lines;
}

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

public class MainActivity extends Activity {
private String inputString = "op British supermarket Tesco (LSE: TSCO) (NASDAQOTH: TSCDY.US) is due to announce its half year results on and this is the extra bit of spill text";

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  TextView bigChar = (TextView) findViewById(R.id.bigChar);
  final TextView sideText = (TextView) findViewById(R.id.sideText);
  final TextView spillText = (TextView) findViewById(R.id.spillText);

  ViewTreeObserver vto = sideText.getViewTreeObserver();
  vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
    @Override
    public void onGlobalLayout() {
      Layout layout = sideText.getLayout();  
      int numOfLines = layout.getLineEnd(2);

      // split the string now
      String spillTextString = inputString.substring(numOfLines, inputString.length());
      spillText.setText(spillTextString);
    }
  });
}
}

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

private String getInvisibleText(final TextView textView) {
  String invisible = null;
  int height    = textView.getHeight();
  int scrollY   = textView.getScrollY();
  Layout staticLayout = textView.getLayout();

  int lastVisibleLineNumber  = staticLayout.getLineForVertical(scrollY+height);
  int start = staticLayout.getLineEnd(lastVisibleLineNumber);
  int end = staticLayout.getLineEnd(textView.getLineCount()-1);

  if (textView.getText().toString() != null
      && !textView.getText().toString().isEmpty() 
      && end > 0
      && textView.getText().toString().length() >= end) {
    invisible = textView.getText().toString().substring(start, end);    
  }
  return invisible;
}

代码示例来源:origin: derry/delion

/**
 * Find the number of lines of text which must be shown in order to display the character at
 * a given index.
 */
private int getLineForIndex(int index) {
  Layout layout = getLayout();
  int endLine = 0;
  while (endLine < layout.getLineCount() && layout.getLineEnd(endLine) < index) {
    endLine++;
  }
  // Since endLine is an index, add 1 to get the number of lines.
  return endLine + 1;
}

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

private void setLayoutListner( final TextView textView ) {
textView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
  @Override
  public void onGlobalLayout() {
    textView.getViewTreeObserver().removeGlobalOnLayoutListener(this);

    final Layout layout = textView.getLayout();

    // Loop over all the lines and do whatever you need with
    // the width of the line
    for (int i = 0; i < layout.getLineCount(); i++) {
      int end = layout.getLineEnd(0);
      SpannableString content = new SpannableString( textView.getText().toString() );
      content.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, end, 0);
      content.setSpan(new StyleSpan(android.graphics.Typeface.NORMAL), end, content.length(), 0);
      textView.setText( content );
    }
  }
});

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

private void setLayoutListner( final TextView textView ) {
  textView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
    @Override
    public void onGlobalLayout() {
      textView.getViewTreeObserver().removeGlobalOnLayoutListener(this);

      final Layout layout = textView.getLayout();

      // Loop over all the lines and do whatever you need with
      // the width of the line
      for (int i = 0; i < layout.getLineCount(); i++) {
        int end = layout.getLineEnd(0);
        SpannableString content = new SpannableString( textView.getText().toString() );
        content.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, end, 0);
        content.setSpan(new StyleSpan(android.graphics.Typeface.NORMAL), end, content.length(), 0);
        textView.setText( content );
      }
    }
  });
}

代码示例来源:origin: blurpy/kouchat-android

/**
 * Gets the text on the given line from the full text of a textview.
 *
 * @param fullText The full text from a textview.
 * @param lineNumber The line number in the textview to get the text from.
 * @param layout The layout of the textview.
 * @return The text found on the given line.
 */
public static String getLineOfText(final String fullText, final int lineNumber, final Layout layout) {
  final int lineStart = layout.getLineStart(lineNumber);
  final int lineEnd = layout.getLineEnd(lineNumber);
  return fullText.substring(lineStart, lineEnd);
}

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

Selection getParagraphs(EditText editor) {    
  Layout layout = new Layout( editor.getEditableText() );

  int selStart = editor.getSelectionStart();
  int selEnd = editor.getSelectionEnd();

  int firstLine = layout.getLineForOffset(selStart);
  int end = selStart == selEnd ? selEnd : selEnd - 1; 
  int lastLine = layout.getLineForOffset(end);

  return new Selection(layout.getLineStart(firstLine), layout.getLineEnd(lastLine));
}

代码示例来源:origin: ZhangQinhao/MONKOVEL

@Override
  public void subscribe(ObservableEmitter<List<String>> e) throws Exception {
    TextPaint mPaint = (TextPaint) mView.getPaint();
    mPaint.setSubpixelText(true);
    Layout tempLayout = new StaticLayout(paragraphstr, mPaint, mView.getContentWidth(), Layout.Alignment.ALIGN_NORMAL, 0, 0, false);
    List<String> linesdata = new ArrayList<String>();
    for (int i = 0; i < tempLayout.getLineCount(); i++) {
      linesdata.add(paragraphstr.substring(tempLayout.getLineStart(i), tempLayout.getLineEnd(i)));
    }
    e.onNext(linesdata);
    e.onComplete();
  }
});

代码示例来源:origin: luhaoaimama1/zone-sdk

/**
 * 得到最多行那个 最后一个字符的位置,与第一个位置 测出宽度 与 扩展字符 相加 如果大于行宽, 就把endPos--,知道小于。
 * 最后 截取字符  0-endPos 然后拼接  扩展字符 去显示即可!
 */
private void setExpand() {
  calExpand = true;
  Layout layout = getLayout();
  int endPos = layout.getLineEnd(maxLine - 1);
  int startPos = layout.getLineStart(maxLine - 1);
  TextPaint pt = getPaint();
  //如果宽度>测量宽度 就继续 --
  while (Layout.getDesiredWidth(getText(), startPos, endPos, pt) + Layout.getDesiredWidth(new SpannedString(EXPAND), pt) > layout.getWidth()
      && --endPos > startPos) {
  }
  SpannableStringBuilder nowSb = new SpannableStringBuilder(getText().subSequence(0, endPos)).append(EXPAND);
  setText(nowSb);
}

相关文章