我正在尝试让 ellipsize 为 TextView 中的单行文本工作。我已经尝试了前面问题下面的所有解决方法(例如 scrollHorizontally、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 中包含这个布局并且不直接使用它?
最佳答案
简单的解决方案是使用 android:singleLine="true"
。
您可以在以下链接中找到相关解决方案。
关于android - 椭圆大小不起作用(对于单行),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31884253/