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


Java Layout.getLineCount方法代码示例

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

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

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

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

}
 
开发者ID:monolifed,项目名称:mininoteview,代码行数:24,代码来源:TextEdit.java

示例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;
}
 
开发者ID:dimorinny,项目名称:show-case-card-view,代码行数:11,代码来源:WrapWidthTextView.java

示例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;
}
 
开发者ID:ceji-longquan,项目名称:ceji_android,代码行数:13,代码来源:ScrollingStrategy.java

示例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);
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:14,代码来源:WrapWidthTextView.java

示例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);
            }
        }
    }
}
 
开发者ID:kawaiiDango,项目名称:pScrobbler,代码行数:36,代码来源:FixedLineTextView.java

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

示例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;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:14,代码来源:WebsiteSettingsPopup.java

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

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

示例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;
}
 
开发者ID:duyp,项目名称:mvvm-template,代码行数:11,代码来源:ViewHelper.java

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

示例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;
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:12,代码来源:RExTextView.java


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