本文整理了Java中android.text.Layout.getLineStart()
方法的一些代码示例,展示了Layout.getLineStart()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Layout.getLineStart()
方法的具体详情如下:
包路径:android.text.Layout
类名称:Layout
方法名:getLineStart
暂无
代码示例来源: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: facebook/litho
float start = getHorizontal(mLayout.getLineStart(line), line);
代码示例来源:origin: seven332/EhViewer
int linebot = layout.getLineForVertical(areabot);
int first = layout.getLineStart(linetop);
int last = layout.getLineEnd(linebot);
代码示例来源:origin: weexteam/weex-hackernews
lastLineStart = layout.getLineStart(mNumberOfLines - 1);
lastLineEnd = layout.getLineEnd(mNumberOfLines - 1);
if (lastLineStart < lastLineEnd) {
代码示例来源: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 lineStart = layout.getLineStart(line);
int lineEnd = layout.getLineEnd(line);
int lineLength = lineEnd - lineStart;
代码示例来源: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: 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: stackoverflow.com
TextView tv = new TextView(context);
ViewTreeObserver vto = tv.getViewTreeObserver();
vto.addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Layout l = tv.getLayout();
int height = tv.getHeight();
int scrollY = tv.getScrollY();
/**
* Key part
*/
int lineCount = l.getLineForVertical(height + scrollY);
int start = l.getLineStart(0);
int end = l.getLineEnd(lineCount - 1);
/**
* Cut string
*/
String s = tv.getText().toString().substring(start, end);
}
}
);
代码示例来源:origin: ahmadaghazadeh/CodeEditor
private int getLineNumberAtPoint(int y) {
int i = topLayoutLine;
while (i <= bottomLayoutLine) {
int lineBound = (mEditor.getLineBounds(i, null) - mEditor.getScrollY()) + 4;
int lineHeight = mEditor.getLineHeight();
if (y >= lineBound || y <= lineBound - lineHeight) {
i++;
} else {
return lineNumbers.getLineForIndex(mEditor.getLayout().getLineStart(i));
}
}
return -1;
}
代码示例来源:origin: stackoverflow.com
public boolean moveDown(Layout layout) {
int start = myTextbox.getSelectionStart();
int end = myTextbox.getSelectionEnd();
if (start != end) {
int min = Math.min(start, end);
int max = Math.max(start, end);
myTextbox.setSelection(max);
if (min == 0 && max == myTextbox.length()) {
return false;
}
return true;
} else {
int line = layout.getLineForOffset(end);
if (line < layout.getLineCount() - 1) {
int move;
if (layout.getParagraphDirection(line) ==
layout.getParagraphDirection(line + 1)) {
float h = layout.getPrimaryHorizontal(end);
move = layout.getOffsetForHorizontal(line + 1, h);
} else {
move = layout.getLineStart(line + 1);
}
myTextbox.setSelection(move);
return true;
}
}
return false;
}
代码示例来源:origin: stackoverflow.com
final Layout layout = editText.getLayout();
final int line = layout.getLineForOffset(editText.getSelectionStart());
final int start = layout.getLineStart(line);
final int end = layout.getLineEnd(line);
editText.getEditableText().setSpan(new EasyEditSpan(), start, end,
代码示例来源: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);
}
代码示例来源:origin: geniusgithub/AndroidDialer
protected boolean up(TextView widget, Spannable buffer) {
if (DBG) {
Log.d(LOG_TAG, "--- up:");
}
Layout layout = widget.getLayout();
int end = getEndPos(widget);
int line = layout.getLineForOffset(end);
if (line > 0) {
int to;
if (layout.getParagraphDirection(line) == layout
.getParagraphDirection(line - 1)) {
float h = layout.getPrimaryHorizontal(end);
to = layout.getOffsetForHorizontal(line - 1, h);
} else {
to = layout.getLineStart(line - 1);
}
mManager.setEndPos(to);
mManager.onCursorMoved();
}
return true;
}
代码示例来源: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;
}
}
代码示例来源:origin: geniusgithub/AndroidDialer
protected boolean down(TextView widget, Spannable buffer) {
if (DBG) {
Log.d(LOG_TAG, "--- down:");
}
Layout layout = widget.getLayout();
int end = getEndPos(widget);
int line = layout.getLineForOffset(end);
if (line < layout.getLineCount() - 1) {
int to;
if (layout.getParagraphDirection(line) == layout
.getParagraphDirection(line + 1)) {
float h = layout.getPrimaryHorizontal(end);
to = layout.getOffsetForHorizontal(line + 1, h);
} else {
to = layout.getLineStart(line + 1);
}
mManager.setEndPos(to);
mManager.onCursorMoved();
}
return true;
}
代码示例来源:origin: MCMrARM/revolution-irc
@Override
protected void onSelectionChanged(int selStart, int selEnd) {
super.onSelectionChanged(selStart, selEnd);
if (getLayout() == null)
return;
String line = getText().subSequence(getLayout().getLineStart(getLayout()
.getLineForOffset(selStart)), selEnd).toString();
boolean isPassword = getPasswordStart(line) != -1;
boolean wasPassword = (getInputType() & InputType.TYPE_TEXT_VARIATION_PASSWORD) != 0;
if (isPassword && !wasPassword) {
Typeface tf = getTypeface();
setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE |
InputType.TYPE_TEXT_VARIATION_PASSWORD | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
setTypeface(tf);
setSelection(selStart, selEnd);
} else if (!isPassword && wasPassword) {
createPasswordSpans();
setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
}
}
代码示例来源:origin: wordpress-mobile/WordPress-Editor-Android
if (mContentEditText.getLayout() != null) {
line = mContentEditText.getLayout().getLineForOffset(selectionStart);
column = mContentEditText.getSelectionStart() - mContentEditText.getLayout().getLineStart(line);
内容来源于网络,如有侵权,请联系作者删除!