Android TextView: getting "W / StaticLayout: maxLineHeight should not be -1. MaxLines: 1 lineCount: 1" when setting text

I set some text in a TextView every 0.5 seconds based on a timer. Every time the timer runs and the text is set, I get this warning, spam in my console.

W / StaticLayout: maxLineHeight should not be -1. maxLines: 1 lineCount: 1

XML code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/title_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="12dp"
        android:layout_marginRight="12dp"
        android:layout_marginTop="12dp"
        android:ellipsize="end"
        android:maxLines="1"
        android:textColor="@color/white"/>

    <TextView
        android:id="@+id/time_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingEnd="4dp"
        android:paddingStart="12dp"
        android:textColor="@color/white"
        android:textSize="12sp"
        tools:text="0:00" />
</RelativeLayout>

Java code:

public void setProgress() {
    // setProgress() called every 0.5 seconds
    // Hardcoded text
    mTimeText.setText("0:05");
}
+17
source share
3 answers

Answering my own question.

Please note that I have two TextView title_textand time_text. Commenting //mTimeText.setText("0:05");, the problem is that the error message was sent by spam, so I thought that the problem should have done something with time_text, but it is not.

title_text. , android:maxLines="1" android:ellipsize="end". , maxLines , . android:ellipsize="end" . , .

, , android:maxLines="1" android:singleLine="true", xml !

mTitleText.setSingleLine(true) java-. , , .

, //mTimeText.setText("0:05"); , . .

+13

, TextView layout_height wrap_content match_parent. layout_height - .


:

android:layout_height="wrap_content" android:layout_height="20dp"

+2

This is a bug in Android, which is marked as fixed, so we have to wait for the next patch: https://issuetracker.google.com/issues/121092510

+2
source

Source: https://habr.com/ru/post/1695178/


All Articles