本文整理匯總了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;
}