本文整理汇总了Java中android.text.Layout.getLineStart方法的典型用法代码示例。如果您正苦于以下问题:Java Layout.getLineStart方法的具体用法?Java Layout.getLineStart怎么用?Java Layout.getLineStart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.Layout
的用法示例。
在下文中一共展示了Layout.getLineStart方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findTextOffset
import android.text.Layout; //导入方法依赖的package包/类
private int findTextOffset(int ypos) {
Layout layout = this.childView.getLayout();
if ( layout == null ) {
return 0;
}
return layout.getLineStart(layout.getLineForVertical(ypos));
}
示例2: onDraw
import android.text.Layout; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
TextPaint paint = getPaint();
paint.setColor(getCurrentTextColor());
paint.drawableState = getDrawableState();
String text = getText().toString();
float lineY = 0;
lineY += getTextSize() * 1f;
final Layout layout = getLayout();
final float desiredLineWidth = getMeasuredWidth();
for (int i = 0, lineCount = layout.getLineCount(); i < lineCount; i++) {
int lineStart = layout.getLineStart(i);
int lineEnd = layout.getLineEnd(i);
String line = text.substring(lineStart, lineEnd);
if (needScale(line) && i < lineCount - 1) {
drawScaledText(line, canvas, lineY, desiredLineWidth, paint);
} else {
canvas.drawText(line, 0, lineY, paint);
}
lineY += getLineHeight();
}
}
示例3: getPrevLine
import android.text.Layout; //导入方法依赖的package包/类
/**
* @return the line above current cursor
*/
@Nullable
private CharSequence getPrevLine(Editable editable, Layout layout, int currentLine) {
if (currentLine - 1 < 0) return null;
int lineStart = layout.getLineStart(currentLine - 1);
int lineEnd = layout.getLineEnd(currentLine - 1);
return editable.subSequence(lineStart, lineEnd);
}
示例4: getNextLine
import android.text.Layout; //导入方法依赖的package包/类
@Nullable
protected CharSequence getNextLine(Editable editable, Layout layout, int currentLine) {
if (currentLine + 1 > layout.getLineCount() - 1) return null;
int lineStart = layout.getLineStart(currentLine + 1);
int lineEnd = layout.getLineEnd(currentLine + 1);
return editable.subSequence(lineStart, lineEnd);
}
示例5: getLineFromIndex
import android.text.Layout; //导入方法依赖的package包/类
/**
* Gets the lineInfo from the index of the letter in the text
*/
public static int getLineFromIndex(int index, int lineCount, Layout layout) {
int line;
int currentIndex = 0;
for (line = 0; line < lineCount; line++) {
currentIndex += layout.getLineEnd(line) - layout.getLineStart(line);
if (currentIndex > index) {
break;
}
}
return line;
}
示例6: getStartIndexAtLine
import android.text.Layout; //导入方法依赖的package包/类
public static int getStartIndexAtLine(EditText editable, int line) {
Layout layout = editable.getLayout();
if (layout != null) {
return layout.getLineStart(line);
}
return 0;
}
示例7: getDebugPosition
import android.text.Layout; //导入方法依赖的package包/类
/**
* @param line - current line
* @param column - column of line
* @return Position (in pixels) for edittext at line and column
*/
public Point getDebugPosition(int line, int column, int gravity) {
Layout layout = getLayout();
if (layout != null) {
int pos = layout.getLineStart(line) + column;
int baseline = layout.getLineBaseline(line);
int ascent = layout.getLineAscent(line);
int offsetHorizontal = (int) layout.getPrimaryHorizontal(pos) + mLinePadding; //x
float y;
int offsetVertical = 0;
if (gravity == Gravity.BOTTOM) {
y = baseline + ascent;
if (verticalScroll != null) {
offsetVertical = (int) ((y + mCharHeight) - verticalScroll.getScrollY());
} else {
offsetVertical = (int) ((y + mCharHeight) - getScrollY());
}
return new Point(offsetHorizontal, offsetVertical);
} else if (gravity == Gravity.TOP) {
y = layout.getLineTop(line);
if (verticalScroll != null) {
offsetVertical = (int) (y - verticalScroll.getScrollY());
} else {
offsetVertical = (int) (y - getScrollY());
}
return new Point(offsetHorizontal, offsetVertical);
}
return new Point(offsetHorizontal, offsetVertical);
}
return new Point();
}
示例8: getLineFromIndex
import android.text.Layout; //导入方法依赖的package包/类
/**
* Gets the lineInfo from the index of the letter in the text
*/
public static int getLineFromIndex(int index, int lineCount, Layout layout) {
int line;
int currentIndex = 0;
for (line = 0; line < lineCount; line++) {
currentIndex += layout.getLineEnd(line) - layout.getLineStart(line);
if (currentIndex >= index) {
break;
}
}
return line;
}
示例9: getLineFromIndex
import android.text.Layout; //导入方法依赖的package包/类
/**
* Gets the line from the index of the letter in the text
*
* @param index
* @param lineCount
* @param layout
* @return
*/
public static int getLineFromIndex(int index, int lineCount, Layout layout) {
int line;
int currentIndex = 0;
for (line = 0; line < lineCount; line++) {
currentIndex += layout.getLineEnd(line) - layout.getLineStart(line);
if (currentIndex > index) {
break;
}
}
return line;
}
示例10: drawTextWithJustify
import android.text.Layout; //导入方法依赖的package包/类
/**
* 重绘文字,两端对齐
*
* @param canvas
*/
private void drawTextWithJustify(Canvas canvas) {
// 文字画笔
TextPaint textPaint = getPaint();
textPaint.setColor(getCurrentTextColor());
textPaint.drawableState = getDrawableState();
String text_str = getText().toString();
// 当前所在行的Y向偏移
int currentLineOffsetY = getPaddingTop();
currentLineOffsetY += getTextSize();
Layout layout = getLayout();
//循环每一行,绘制文字
for (int i = 0; i < layout.getLineCount(); i++) {
int lineStart = layout.getLineStart(i);
int lineEnd = layout.getLineEnd(i);
//获取到TextView每行中的内容
String line_str = text_str.substring(lineStart, lineEnd);
// 获取每行字符串的宽度(不包括字符间距)
float desiredWidth = StaticLayout.getDesiredWidth(text_str, lineStart, lineEnd, getPaint());
if (isLineNeedJustify(line_str)) {
//最后一行不需要重绘
if (i == layout.getLineCount() - 1) {
canvas.drawText(line_str, getPaddingLeft(), currentLineOffsetY, textPaint);
} else {
drawJustifyTextForLine(canvas, line_str, desiredWidth, currentLineOffsetY);
}
} else {
canvas.drawText(line_str, getPaddingLeft(), currentLineOffsetY, textPaint);
}
//更新行Y向偏移
currentLineOffsetY += getLineHeight();
}
}
示例11: calculatorCharPositionToLeft
import android.text.Layout; //导入方法依赖的package包/类
/**
* 计算字符距离控件左侧的位移
*
* @param line 字符所在行
* @param charOffset 字符偏移量
*/
private float calculatorCharPositionToLeft(int line, int charOffset) {
String text_str = getText().toString();
Layout layout = getLayout();
int lineStart = layout.getLineStart(line);
int lineEnd = layout.getLineEnd(line);
String line_str = text_str.substring(lineStart, lineEnd);
if (line_str.equals("\n"))
return getPaddingLeft();
// 最左侧
if (lineStart == charOffset)
return getPaddingLeft();
// 最右侧
if (charOffset == lineEnd - 1)
return mViewTextWidth + getPaddingLeft();
float desiredWidth = StaticLayout.getDesiredWidth(text_str, lineStart, lineEnd, getPaint());
// 中间位置
// 计算相邻字符之间需要填充的宽度
// (TextView内容的实际宽度 - 该行字符串的宽度)/(字符个数-1)
float insert_blank = (mViewTextWidth - desiredWidth) / (line_str.length() - 1);
// 计算当前字符左侧所有字符的宽度
float allLeftCharWidth = StaticLayout.getDesiredWidth(text_str.substring(lineStart, charOffset), getPaint());
// 相邻字符之间需要填充的宽度 + 当前字符左侧所有字符的宽度
return insert_blank * (charOffset - lineStart) + allLeftCharWidth + getPaddingLeft();
}
示例12: action
import android.text.Layout; //导入方法依赖的package包/类
private boolean action(int what, TextView widget, Spannable buffer) {
Layout layout = widget.getLayout();
int padding = widget.getTotalPaddingTop() + widget.getTotalPaddingBottom();
int areatop = widget.getScrollY();
int areabot = (widget.getHeight() + areatop) - padding;
int linetop = layout.getLineForVertical(areatop);
int linebot = layout.getLineForVertical(areabot);
int first = layout.getLineStart(linetop);
int last = layout.getLineEnd(linebot);
MyURLSpan[] candidates = (MyURLSpan[]) buffer.getSpans(first, last, MyURLSpan.class);
int a = Selection.getSelectionStart(buffer);
int b = Selection.getSelectionEnd(buffer);
int selStart = Math.min(a, b);
int selEnd = Math.max(a, b);
if (selStart < 0 && buffer.getSpanStart(FROM_BELOW) >= 0) {
selEnd = buffer.length();
selStart = selEnd;
}
if (selStart > last) {
selEnd = ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED;
selStart = ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED;
}
if (selEnd < first) {
selEnd = -1;
selStart = -1;
}
int beststart;
int bestend;
int i;
switch (what) {
case 1:
if (selStart != selEnd) {
MyURLSpan[] link = (MyURLSpan[]) buffer.getSpans(selStart, selEnd, MyURLSpan
.class);
if (link.length == 1) {
link[0].onClick(widget);
break;
}
return false;
}
return false;
case 2:
beststart = -1;
bestend = -1;
for (i = 0; i < candidates.length; i++) {
int end = buffer.getSpanEnd(candidates[i]);
if ((end < selEnd || selStart == selEnd) && end > bestend) {
beststart = buffer.getSpanStart(candidates[i]);
bestend = end;
}
}
if (beststart >= 0) {
Selection.setSelection(buffer, bestend, beststart);
return true;
}
break;
case 3:
beststart = ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED;
bestend = ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED;
for (i = 0; i < candidates.length; i++) {
int start = buffer.getSpanStart(candidates[i]);
if ((start > selStart || selStart == selEnd) && start < beststart) {
beststart = start;
bestend = buffer.getSpanEnd(candidates[i]);
}
}
if (bestend < Integer.MAX_VALUE) {
Selection.setSelection(buffer, beststart, bestend);
return true;
}
break;
}
return false;
}