Android 在TextView中检查文本在一行上

Android 在TextView中检查文本在一行上,android,textview,Android,Textview,如何检测TextView中的文本是否在一行上 如果它超过一行,我想使用128dp工具栏 如果是单行,我想使用48dp,您可以将android:singleLine属性设置为true 请参阅如果返回1,则文本为单行,如下所示 int lineCount=mTextView.getLineCount(); 试试这个: if(yourTv.getLineCount() > 1) { yourTv.setTextSize(); else { yourTv.setTextSize(

如何检测TextView中的文本是否在一行上

如果它超过一行,我想使用128dp工具栏

如果是单行,我想使用48dp,您可以将android:singleLine属性设置为true


请参阅

如果返回1,则文本为单行,如下所示

int lineCount=mTextView.getLineCount();
试试这个:

if(yourTv.getLineCount() > 1) {
    yourTv.setTextSize();
else {
    yourTv.setTextSize();
}

您可以使用StaticLayout

    TextPaint textPaint = new TextPaint();
    textPaint.setTypeface(textView.getTypeface());
    textPaint.setTextSize(textView.getTextSize());
    textPaint.setTextAlign(Paint.Align.ALIGN_NORMAL);
    StaticLayout staticLayout = new StaticLayout(textString, textPaint, widthTextView, Layout.Alignment.ALIGN_NORMAL, 1f, 0f, true);
    if (1 == staticLayout.getLineCount()) {
        //do smth
    } else {
        //do smth else
    }

android:lines=1您想要实现什么?可能与-TextView重复。getLineCount@Doomsknight,始终返回0@AskQuestion这意味着尚未构建内部布局。我不想使用单线属性。请再读一遍我写的。