当前位置: 首页>>代码示例>>Java>>正文


Java Layout.getLineStart方法代码示例

本文整理汇总了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));		
}
 
开发者ID:ceji-longquan,项目名称:ceji_android,代码行数:10,代码来源:ScrollingStrategy.java

示例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();
    }
}
 
开发者ID:marcoscgdev,项目名称:HeaderDialog,代码行数:29,代码来源:ContentTextViewJustified.java

示例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);
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:11,代码来源:IndentEditText.java

示例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);
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:8,代码来源:IndentEditText.java

示例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;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:16,代码来源:LineUtils.java

示例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;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:8,代码来源:LineUtils.java

示例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();
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:41,代码来源:HighlightEditor.java

示例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;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:16,代码来源:LineUtils.java

示例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;
}
 
开发者ID:ujjwalagrawal17,项目名称:CodeCompilerApp,代码行数:22,代码来源:LineUtils.java

示例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();
    }
}
 
开发者ID:devilist,项目名称:AdvancedTextView,代码行数:42,代码来源:SelectableTextView.java

示例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();

}
 
开发者ID:devilist,项目名称:AdvancedTextView,代码行数:40,代码来源:SelectableTextView.java

示例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;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:75,代码来源:LongClickableLinkMovementMethod.java


注:本文中的android.text.Layout.getLineStart方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。