當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。