我有一个listView,其中包含由下面的xml-layout定义的自定义对象.我希望带有id"info"的textView在一行上进行椭圆化,我尝试使用这些属性
android:singleLine="true"
android:ellipsize="end"
Run Code Online (Sandbox Code Playgroud)
没有成功.
如果我将layout_width设置为固定宽度,例如
android:layout_width="100px"
Run Code Online (Sandbox Code Playgroud)
文本被截断了.但出于便携性原因,这不是一个可接受的解决方案.
你能发现问题吗?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="5px"
>
<TextView
android:id="@+id/destination"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="22dp"
android:paddingLeft="5px"
/>
<TextView
android:id="@+id/date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="15dp"
android:paddingLeft="5px"
/>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/info_table"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="5px"
android:paddingTop="10px"
>
<TableRow>
<TextView
android:id="@+id/driver_label"
android:gravity="right"
android:paddingRight="5px"
android:text="@string/driver_label" />
<TextView
android:id="@+id/driver" />
</TableRow>
<TableRow>
<TextView
android:id="@+id/passenger_label"
android:gravity="right"
android:paddingRight="5px"
android:text="@string/passenger_label" />
<TextView
android:id="@+id/passengers" />
</TableRow>
<TableRow>
<TextView
android:id="@+id/info_label"
android:gravity="right"
android:paddingRight="5px"
android:text="@string/info_label"/>
<TextView
android:id="@+id/info"
android:layout_width="fill_parent"
android:singleLine="true"
android:ellipsize="end" />
</TableRow>
</TableLayout>
Run Code Online (Sandbox Code Playgroud)
我在android xml文件中使用android:ellipsize ="end",令人惊讶的是我没有得到我想要的布局,3点(...)显示但是在那之后还有另一个字被截断.这也是一个"不总是"的行为,检查附加的ListView,有时,行为是正常的,有时不是.
这是我的设备布局的屏幕截图,

我不知道为什么会这样.这是我的xml文件,有tv_news_content TextView的问题-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/white" >
<ImageView
android:id="@+id/iv_next_tier"
android:layout_width="18dp"
android:layout_height="21dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:src="@drawable/right_arrow" >
</ImageView>
<TextView
android:id="@+id/tv_news_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="7dp"
android:layout_marginRight="5dp"
android:layout_marginTop="3dp"
android:layout_toLeftOf="@+id/iv_next_tier"
android:ellipsize="end"
android:maxLines="2"
android:text="News Title"
android:textColor="@color/black"
android:textSize="17dp"
android:textStyle="bold" />
<TextView
android:id="@+id/tv_news_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/tv_news_title"
android:layout_below="@+id/tv_news_title"
android:layout_marginRight="5dp"
android:layout_toLeftOf="@+id/iv_next_tier"
android:ellipsize="end"
android:maxLines="2"
android:text="News Contents"
android:textColor="@color/black_light"
android:textSize="15dp" />
<View
android:id="@+id/view"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_below="@+id/tv_news_content"
android:layout_marginTop="5dp" />
Run Code Online (Sandbox Code Playgroud)
为了清楚起见,tv_news_title是最顶级的粗体TextView,而iv_next_tier是右侧的小箭头型ImageView.&tv_news_content是我遇到问题的TextView.
任何解决方案为什么我没有获得所需的输出?期望的输出意味着始终正常的行为 …