【发布时间】:2023-03-22 11:38:01
【问题描述】:
我正在尝试让椭圆大小适用于 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中包含这个布局并且不直接使用它?
【问题讨论】:
-
文本是否在某个时候被截断?
-
是的,它只是被切断了。由于 maxLines="1" 不会在下一行中换行,但也不会像应有的那样椭圆化....
-
只有 wrap_content 才会有问题,因为 wrap_content 将允许 TextView 可以根据需要展开(包括跑出屏幕)
-
你是如何包含它的?我假设您的意思是使用
<include>,但您是否在<include>标签中设置了任何属性? -
不,只有