问题
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" />
回答1:
If you want to fix the number of lines ex: 3 just use android:lines="3" in xml.
回答2:
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);
回答3:
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.
来源:https://stackoverflow.com/questions/35195585/android-minlines-and-maxlines-arent-working-together-in-same-textview