Два TextViews рядом, только один для многоточия?
Я хочу иметь дваTextView
элементы отображаются рядом (в элементе списка), один выровнен по левому краю, другой по правому краю. Что-то вроде:
|<TextView> <TextView>|
(|
представляют конечности экрана)
Тем не менееTextView
слева может быть содержимое, которое слишком длинное, чтобы уместиться на экране. В этом случае, я хочу, чтобы он имел размер эллипса, но все еще показывает все праваTextView
, Что-то вроде:
|This is a lot of conte...<TextView>|
У меня были многочисленные попытки сделать это, используя обаLinearLayout
а такжеRelativeLayout
и единственное решение, которое я придумал, это использоватьRelativeLayout
и положитьmarginRight
налевоTextView
достаточно большой, чтобы очистить правоTextView
, Как вы можете себе представить, однако, это не оптимально.
Есть ли другие решения?
Финал,LinearLayout
решение:
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="horizontal"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:inputType="text"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="0"
android:layout_gravity="right"
android:inputType="text"
/>
</LinearLayout>
Старый,TableLayout
решение:
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
android:shrinkColumns="0"
>
<TableRow>
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
/>
<TextView android:id="@+id/date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true"
android:ellipsize="none"
android:gravity="right"
/>
</TableRow>
</TableLayout>