【问题标题】:Android minLines and maxLines aren't working together in same TextViewAndroid minLines 和 maxLines 不能在同一个 TextView 中一起工作
【发布时间】:2016-05-13 17:51:31
【问题描述】:

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

但问题是我想在每个 TextView 中显示最多 3 行,但如果 TextView 的长度很小,它不会为我提供好的结果。但是如果文本很大,它会很好用。

当我添加android:maxLines="3" 并且文字很小时,它会破坏我的布局,就像

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

给我一​​个解决这个问题的方法。我的每个TextView 看起来像:

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

【问题讨论】:

  • 我遇到了同样的问题,如果我设置 min 和 max 它只会使它成为最小行长度。你找到解决办法了吗?
  • 请给我看看你的用户界面

标签: android listview textview


【解决方案1】:

如果你想修正行数 ex: 3 只需在 xml 中使用 android:lines="3"。

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 不幸的是,它不起作用,而且还占用了一些额外的空间
    • textview 现在有什么问题?@Anshul
    • 如果文本很小,第三行会占用额外的空间,我不希望这样。
    • 删除 android:lines="3" 并检查 @Anshul
    【解决方案3】:

    如果您想修复 TextView 文本,请使用:

    android:ems="10"
    

    或任何您想要代替 10 的值。 android:emssetEms(n) 将 TextView 的宽度设置为适合 n 'M' 个字母的文本,而不管实际的文本扩展名和文本大小。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-09
      • 1970-01-01
      • 2021-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-11
      • 1970-01-01
      相关资源
      最近更新 更多