本文整理汇总了Java中android.text.Layout.getLineCount方法的典型用法代码示例。如果您正苦于以下问题:Java Layout.getLineCount方法的具体用法?Java Layout.getLineCount怎么用?Java Layout.getLineCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.Layout
的用法示例。
在下文中一共展示了Layout.getLineCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeReleaseOffset
import android.text.Layout; //导入方法依赖的package包/类
private int computeReleaseOffset(int space) {
// This is simpler than it looks: we must pass whole lines.
String logPrefix = logPrefix();
Layout layout = mView.getLayout();
int count = layout.getLineCount();
int removed = 0;
LOG.v(logPrefix, "computeReleaseOffset:", "space:", space, "lineCount:", count);
int removeLine = 0;
for (int i = count - 1; i >= 0; i--) {
layout.getLineBounds(i, mTmp);
removed += mTmp.height();
if (removed >= space) {
removeLine = i;
break;
}
}
// We have to remove line i and all subsequent lines.
LOG.i(logPrefix, "computeReleaseOffset:", "removing line:", removeLine, "and subsequent.");
return Math.max(layout.getOffsetForHorizontal(removeLine, 0) - 1, 0);
}
示例2: onMeasure
import android.text.Layout; //导入方法依赖的package包/类
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
Layout layout = getLayout();
if (layout != null) {
int lineCount = layout.getLineCount();
if (lineCount > 0 && layout.getEllipsisCount(lineCount - 1) > 0) {
setSingleLine(false);
setMaxLines(2);
TypedArray a = getContext().obtainStyledAttributes(null, R.styleable.TextAppearance, 16842817, 16973892);
int textSize = a.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize, 0);
if (textSize != 0) {
setTextSize(0, (float) textSize);
}
a.recycle();
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
}
示例3: isTitleTruncated
import android.text.Layout; //导入方法依赖的package包/类
public boolean isTitleTruncated() {
if (this.mTitleTextView == null) {
return false;
}
Layout titleLayout = this.mTitleTextView.getLayout();
if (titleLayout == null) {
return false;
}
int lineCount = titleLayout.getLineCount();
for (int i = 0; i < lineCount; i++) {
if (titleLayout.getEllipsisCount(i) > 0) {
return true;
}
}
return false;
}
示例4: moveCursor
import android.text.Layout; //导入方法依赖的package包/类
private void moveCursor(int x, int y)
{
x -= edit.getPaddingLeft();
y -= edit.getPaddingTop();
Layout l = edit.getLayout();
int offset;
int line = l.getLineForVertical(y);
if(line == 0 && y < l.getLineTop(line))
{
offset = 0;
}
else if(line >= l.getLineCount() - 1 && y >= l.getLineTop(line + 1))
{
offset = l.getText().length();
}
else
{
offset = l.getOffsetForHorizontal(line, x);
}
edit.setSelection(offset);
}
示例5: getMaxLineWidth
import android.text.Layout; //导入方法依赖的package包/类
private float getMaxLineWidth(Layout layout) {
float max_width = 0.0f;
int lines = layout.getLineCount();
for (int i = 0; i < lines; i++) {
if (layout.getLineWidth(i) > max_width) {
max_width = layout.getLineWidth(i);
}
}
return max_width;
}
示例6: isAtEnd
import android.text.Layout; //导入方法依赖的package包/类
@Override
public boolean isAtEnd() {
int ypos = bookView.getScrollY() + bookView.getHeight();
Layout layout = this.childView.getLayout();
if ( layout == null ) {
return false;
}
int line = layout.getLineForVertical(ypos);
return line == layout.getLineCount() -1;
}
示例7: getMaxWidth
import android.text.Layout; //导入方法依赖的package包/类
private int getMaxWidth(Layout layout) {
int linesCount = layout.getLineCount();
if (linesCount < 2) {
return 0;
}
float maxWidth = 0;
for (int i = 0; i < linesCount; i++) {
maxWidth = Math.max(maxWidth, layout.getLineWidth(i));
}
return (int) Math.ceil(maxWidth);
}
示例8: onMeasure
import android.text.Layout; //导入方法依赖的package包/类
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
final Layout layout = getLayout();
if (layout != null) {
final int lineCount = layout.getLineCount();
if (lineCount > 0) {
final int ellipsisCount = layout.getEllipsisCount(lineCount - 1);
if (ellipsisCount > 0) {
final float textSize = getTextSize();
if (textSize <= MIN_TEXT_SIZE)
return;
if (mOriginalSize == null) {
mOriginalSize = textSize;
}
if (mOriginalHeight == 0) {
mOriginalHeight = getMeasuredHeight();
}
float before = mOriginalSize;
// textSize is already expressed in pixels
setTextSize(TypedValue.COMPLEX_UNIT_PX, (textSize - 1));
mOriginalSize = before;
// recursion
measure(widthMeasureSpec, heightMeasureSpec);
setHeight(mOriginalHeight);
}
}
}
}
示例9: 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();
}
}
示例10: getLineForIndex
import android.text.Layout; //导入方法依赖的package包/类
/**
* 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;
}
示例11: 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);
}
示例12: computeMaxLineCount
import android.text.Layout; //导入方法依赖的package包/类
private int computeMaxLineCount(Layout layout) {
int availableHeight = getMeasuredHeight() - getPaddingTop() - getPaddingBottom();
for (int i = 0; i < layout.getLineCount(); i++) {
if (availableHeight < layout.getLineBottom(i)) {
return i;
}
}
return layout.getLineCount();
}
示例13: isEllipsed
import android.text.Layout; //导入方法依赖的package包/类
public static boolean isEllipsed(@NonNull TextView textView) {
Layout layout = textView.getLayout();
if (layout != null) {
int lines = layout.getLineCount();
if (lines > 0) {
return IntStream.range(0, lines).anyMatch(line -> layout.getEllipsisCount(line) > 0);
}
}
return false;
}
示例14: 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();
}
}
示例15: getLastLineHeight
import android.text.Layout; //导入方法依赖的package包/类
private int getLastLineHeight() {
Layout layout = getLayout();
if (layout != null) {
int lineCount = layout.getLineCount();
if (lineCount > 0) {
//行的底部距离view顶部的高度, 最后一行的LineTop通常会等于View的height
return layout.getLineTop(lineCount) - layout.getLineTop(lineCount - 1);
}
}
return 0;
}