Android minLines and maxLines do not work together in the same TextView

Here I have only 1 element in ListView, and I show two different TextViewsdifferent colors at the end of the element ListView.

But the problem is that I want to show a maximum of 3 lines each TextView, but this does not give me a good result if the length TextViewis small. But it works well if the text is large.

When I add android:maxLines="3"and the text is small, it destroys my layout, for example

And when I add android:minLines="2"and the text is large, it shows the full text, for example

Give me a way to overcome this problem. Each mine TextViewlooks like this:

  <TextView
            android:id="@+id/tv_previous_story"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="3dp"
            android:maxLines="3"
            android:textColor="@color/text_color"
            android:textSize="@dimen/privacy_text_size" />
+4
3

ex: 3, android: lines = "3" xml.

0

android:layout_width="match_parent",

<TextView
                    android:id="@+id/tv_previous_story"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="3dp"
                    android:ellipsize="none"
                    android:maxLines="3"
                    android:singleLine="false"
                    android:textColor="@color/black"
                    android:textSize="@dimen/font_normal_size" />

tv_previous_story.setMaxLines(3);
0

If you want to correct TextView text, use:

android:ems="10"

or whatever value you want instead of 10. android:emsor setEms(n)sets the width of the TextView to match the text of the letters n 'M' regardless of the actual expansion of the text and the size of the text.

-2
source

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


All Articles