4

Here I have only 1 item in ListView and I'm showing two different TextViews of different colors at the end of the ListView item.

But the issue is I wanna show maximum 3 lines of each TextView but it's not providing me a good result if length of TextView is small. But it works well if text is large.

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

And when I add android:minLines="2" and text is large, it shows complete text like

Give me a way to overcome this problem. My each TextView looks like:

  <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" />
Siri
  • 143
  • 11

3 Answers3

0

If you want to fix the number of lines ex: 3 just use android:lines="3" in xml.

Ragesh Ramesh
  • 3,470
  • 2
  • 14
  • 20
0

Change 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" />

OR

tv_previous_story.setMaxLines(3);
Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142
-2

If you want to fix the TextView text use :

android:ems="10"

or any value you want in place of 10. android:ems or setEms(n) sets the width of a TextView to fit a text of n 'M' letters regardless of the actual text extension and text size.

user5716019
  • 598
  • 4
  • 17