Android minLines和maxLines无法在同一个TextView中一起使用 [英] Android minLines and maxLines aren't working together in same TextView

查看:54
本文介绍了Android minLines和maxLines无法在同一个TextView中一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里,在 ListView 中只有1个项目,并且在 ListView 项的末尾显示了两个不同颜色的不同 TextViews .

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.

但是问题是我想最多显示每个 TextView 的3行,但是如果 TextView 的长度很小,则不能为我提供良好的结果.但是,如果文本较大,效果很好.

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.

当我添加 android:maxLines ="3" 且文本很小时,它会破坏我的布局,如

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

当我添加 android:minLines ="2" 且文本较大时,它会显示完整的文本,例如

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

请给我一种解决此问题的方法.我的每个 TextView 如下:

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

推荐答案

更改 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);

这篇关于Android minLines和maxLines无法在同一个TextView中一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆