本文整理了Java中android.text.Layout.getLineCount()
方法的一些代码示例,展示了Layout.getLineCount()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Layout.getLineCount()
方法的具体详情如下:
包路径:android.text.Layout
类名称:Layout
方法名:getLineCount
暂无
代码示例来源:origin: stackoverflow.com
Layout l = textview.getLayout();
if (l != null) {
int lines = l.getLineCount();
if (lines > 0)
if (l.getEllipsisCount(lines-1) > 0)
Log.d(TAG, "Text is ellipsized");
}
代码示例来源:origin: facebook/litho
/**
* @param layout A prepared text layout object
* @return The (zero-indexed) line number at which the text in this layout will be ellipsized, or
* -1 if no line will be ellipsized.
*/
private static int getEllipsizedLineNumber(Layout layout) {
for (int i = 0; i < layout.getLineCount(); ++i) {
if (layout.getEllipsisCount(i) > 0) {
return i;
}
}
return -1;
}
代码示例来源:origin: stackoverflow.com
Layout layout = textview1.getLayout();
if(layout != null) {
int lines = layout.getLineCount();
if(lines > 0) {
int ellipsisCount = layout.getEllipsisCount(lines-1);
if ( ellipsisCount > 0) {
Log.d(TAG, "Text is ellipsized");
}
}
}
代码示例来源:origin: stackoverflow.com
final int lineCount = layout.getLineCount();
if (lineCount > 0) {
final int ellipsisCount = layout.getEllipsisCount(lineCount - 1);
代码示例来源:origin: hanks-zyh/HTextView
@Override
protected void drawFrame(Canvas canvas) {
Layout layout = mHTextView.getLayout();
int gapIndex = 0;
for (int i = 0; i < layout.getLineCount(); i++) {
int lineStart = layout.getLineStart(i);
int lineEnd = layout.getLineEnd(i);
float lineLeft = layout.getLineLeft(i);
float lineBaseline = layout.getLineBaseline(i);
String lineText = mText.subSequence(lineStart, lineEnd).toString();
for (int c = 0; c < lineText.length(); c++) {
int alpha = alphaList.get(gapIndex);
mPaint.setAlpha((int) ((255 - alpha) * progress + alpha));
canvas.drawText(String.valueOf(lineText.charAt(c)), lineLeft, lineBaseline, mPaint);
lineLeft += gapList.get(gapIndex++);
}
}
}
}
代码示例来源:origin: facebook/litho
private static Layout setupWidthTestTextLayout() {
final Layout layout = mock(Layout.class);
final int fullWidth = FULL_TEXT_WIDTH;
final int minimalWidth = MINIMAL_TEXT_WIDTH;
when(layout.getLineCount()).thenReturn(2);
when(layout.getWidth()).thenReturn(fullWidth);
when(layout.getLineRight(anyInt())).thenReturn((float) minimalWidth);
return layout;
}
}
代码示例来源:origin: stackoverflow.com
if (maxLines != -1) {
Layout layout = createWorkingLayout(workingText);
if (layout.getLineCount() > maxLines) {
workingText = fullText.substring(0, layout.getLineEnd(maxLines - 1)).trim();
while (createWorkingLayout(workingText + ELLIPSIS).getLineCount() > maxLines) {
代码示例来源:origin: facebook/litho
@VisibleForTesting
public static int resolveWidth(
int widthSpec, Layout layout, boolean minimallyWide, int minimallyWideThreshold) {
final int fullWidth = SizeSpec.resolveSize(widthSpec, layout.getWidth());
if (minimallyWide && layout.getLineCount() > 1) {
final int minimalWidth = SizeSpec.resolveSize(widthSpec, LayoutMeasureUtil.getWidth(layout));
if (fullWidth - minimalWidth > minimallyWideThreshold) {
return minimalWidth;
}
}
return fullWidth;
}
代码示例来源:origin: HotBitmapGG/bilibili-android-client
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Layout layout = new StaticLayout(getText(), mTextPaintOutline,
measureWidth(widthMeasureSpec), Layout.Alignment.ALIGN_CENTER,
mSpacingMult, mSpacingAdd, mIncludePad);
int ex = (int) (mBorderSize * 2 + 1);
setMeasuredDimension(measureWidth(widthMeasureSpec) + ex,
measureHeight(heightMeasureSpec) * layout.getLineCount() + ex);
}
代码示例来源:origin: nickbutcher/plaid
int currentEndRunLeft = 0;
int currentEndRunTop = 0;
List<Run> runs = new ArrayList<>(endLayout.getLineCount());
代码示例来源:origin: facebook/TextLayoutBuilder
/**
* Returns the leftmost position of the layout. This is helpful when there's space between the
* layout's left bound and its content's (lines) leftmost bound, e.g. StaticLayout when the text
* alignment is not ALIGN_NORMAL.
*/
public static int getContentLeft(Layout layout) {
if (layout == null || layout.getLineCount() == 0) {
return 0;
}
int left = Integer.MAX_VALUE;
for (int i = 0; i < layout.getLineCount(); i++) {
left = Math.min(left, (int) layout.getLineLeft(i));
}
return left;
}
}
代码示例来源:origin: facebook/litho
final int lineCount = newLayout.getLineCount();
if (lineCount < minLines) {
final TextPaint paint = newLayout.getPaint();
代码示例来源:origin: stackoverflow.com
ViewTreeObserver vto = textview.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Layout l = textview.getLayout();
if ( l != null){
int lines = l.getLineCount();
if ( lines > 0)
if ( l.getEllipsisCount(lines-1) > 0)
Log.d(TAG, "Text is ellipsized");
}
}
});
代码示例来源:origin: stackoverflow.com
ViewTreeObserver vto = textview.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Layout l = textview.getLayout();
if ( l != null){
int lines = l.getLineCount();
if ( lines > 0)
if ( l.getEllipsisCount(lines-1) > 0)
Log.d(TAG, "Text is ellipsized");
}
}
});
代码示例来源:origin: sjwall/MaterialTapTargetPrompt
/**
* Calculates the maximum width line in a text layout.
*
* @param textLayout The text layout
* @return The maximum length line
*/
public static float calculateMaxTextWidth(@Nullable final Layout textLayout)
{
float maxTextWidth = 0f;
if (textLayout != null)
{
for (int i = 0, count = textLayout.getLineCount(); i < count; i++)
{
maxTextWidth = Math.max(maxTextWidth, textLayout.getLineWidth(i));
}
}
return maxTextWidth;
}
代码示例来源:origin: facebook/TextLayoutBuilder
/**
* Returns the width of the layout.
*
* @param layout The layout.
* @return The width of the layout.
*/
public static int getWidth(Layout layout) {
if (layout == null) {
return 0;
}
// Supplying VERY_WIDE will make layout.getWidth() return a very large value.
int count = layout.getLineCount();
int maxWidth = 0;
for (int i = 0; i < count; i++) {
maxWidth = Math.max(maxWidth, (int) layout.getLineRight(i));
}
return maxWidth;
}
代码示例来源:origin: sjwall/MaterialTapTargetPrompt
@Test
public void testCalculateMaxTextWidth()
{
Layout layout = mock(Layout.class);
when(layout.getLineCount()).thenReturn(3);
when(layout.getLineWidth(0)).thenReturn(10f);
when(layout.getLineWidth(1)).thenReturn(100f);
when(layout.getLineWidth(2)).thenReturn(50f);
assertEquals(100f, PromptUtils.calculateMaxTextWidth(layout), 0);
}
代码示例来源:origin: curtis2/SuperVideoPlayer
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Layout layout = new StaticLayout(getText(), mTextPaintOutline, measureWidth(widthMeasureSpec), Layout.Alignment.ALIGN_CENTER, mSpacingMult, mSpacingAdd, mIncludePad);
int ex = (int) (mBorderSize * 2 + 1);
setMeasuredDimension(measureWidth(widthMeasureSpec) + ex, measureHeight(heightMeasureSpec) * layout.getLineCount() + ex);
}
代码示例来源:origin: facebook/TextLayoutBuilder
@Test
public void testSingleLine() {
mLayout = mBuilder.setText(LONG_TEXT).setSingleLine(true).setWidth(1000).build();
assertEquals(mLayout.getLineCount(), 1);
}
代码示例来源:origin: facebook/TextLayoutBuilder
@Test
public void testMaxLines() {
mLayout = mBuilder.setText(LONG_TEXT).setMaxLines(2).setWidth(1000).build();
assertEquals(mLayout.getLineCount(), 2);
}
内容来源于网络,如有侵权,请联系作者删除!