【问题标题】:Ellipsize not working (for single line)Ellipsize 不起作用(对于单行)
【发布时间】:2023-03-22 11:38:01
【问题描述】:

我正在尝试让椭圆大小适用于 TextView 中的单行文本。我已经尝试了之前问题下方的所有解决方法(例如 scrollHorizo​​ntally、singleLine、lines 等),但似乎没有任何反应。这是我的代码(在 HTC One M8 (5.0.1) 上测试):

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="@drawable/file_tile_background" >

<ImageView
    android:id="@+id/file_tile_imageview"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="24dp"
    android:src="@drawable/ic_insert_drive_file_black"
    android:contentDescription="@string/file_tile_imageview_description" />

<TextView
    android:id="@+id/file_tile_textview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_toRightOf="@id/file_tile_imageview"
    android:text="@string/file_tile_textview_fileName"
    android:maxLines="1"
    android:ellipsize="start"
    android:textSize="16sp" />
</RelativeLayout>

编辑:也许它不喜欢我在activity_main.xml中包含这个布局并且不直接使用它?

【问题讨论】:

  • 文本是否在某个时候被截断?
  • 是的,它只是被切断了。由于 maxLines="1" 不会在下一行中换行,但也不会像应有的那样椭圆化....
  • 只有 wrap_content 才会有问题,因为 wrap_content 将允许 TextView 可以根据需要展开(包括跑出屏幕)
  • 你是如何包含它的?我假设您的意思是使用&lt;include&gt;,但您是否在&lt;include&gt; 标签中设置了任何属性?
  • 不,只有

标签: android textview


【解决方案1】:

简单的解决方案是使用android:singleLine="true"

您可以在以下链接中找到相关的解决方案。

TextView's ellipsize not working on maxLines = 1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-14
    • 1970-01-01
    • 2018-05-29
    • 2013-01-19
    • 2016-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多