我试图获得两个并排且居中的文本视图——允许它们随着数据的增长而增长。当文本为
大,我在省略它。
目前,当我在两个框中有以下文字时
-
一个大的长单词列表,将另一个文本视图推出
-
Foobar公司
两者都受到挤压。
在这种情况下,我希望“Foobar”被完全显示,而较长的TextView会留出一些空间——例如
...the other TextView out Foobar
我现在得到的是
...that pushes the other TextView out ...ar
我的尝试如下。
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:maxLines="1"
android:ellipsize="start"
android:textSize="20dp"
android:text="A big long list of words that pushes the other TextView out" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:maxLines="1"
android:ellipsize="start"
android:textSize="20dp"
android:text="Foobar" />
</LinearLayout>
我还尝试了一个相对输出(见下文)——带有minWidth——但这只是将最右边的TextView完全从父视图中挤出!
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:maxLines="1"
android:ellipsize="start"
android:textSize="20dp"
android:text="A big long list of words that pushes the other TextView out" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/textView1"
android:minWidth="100dp"
android:maxLines="1"
android:ellipsize="start"
android:textSize="20dp"
android:text="Foobar" />
</RelativeLayout>
有人知道怎么做吗?