小编zmi*_*man的帖子

在TextView中使用'ellipsize'并在必要时仅展开视图

我有2个TextView连续和2个要求:

1)如果第一个TextView不是太宽,它应该如下所示

| [1 text] [2 text] |

2)如果第一个TextView太宽,它应该如下所示

| [1 text text tex ...] [2 text] |

第二个要求很简单,你可以使用android:layout_weight ="1",例如:

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
>
    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:singleLine="true"
        android:ellipsize="end"
        android:text="1 text text text text text"
    />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="2 text"
    />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

,但如果第一个TextView包含一个短文本,它看起来像

| [1 text] [2 text] |

,这是不可接受的.

那么如何同时满足1)和2)的要求呢?

android android-layout

4
推荐指数
1
解决办法
1572
查看次数

标签 统计

android ×1

android-layout ×1