Моя проблема очень похожа на Как получить макет, где один текст может расти и эллипсироваться, но не сожрать другие элементы на макете, но читать дальше ниже, почему я не могу использовать TableLayouts, как предлагалось там.
Я пытаюсь создать строку listview, которая выглядит примерно так:
| TextView | Просмотреть 1 | Просмотр 2 |
Все представления содержат элементы переменной ширины. TextView имеет значение ellipsize = "end". Вид 1 должен совпадать слева от TextView, а View 2 - в правой части экрана. Таким образом, обычно между пробелами между View 1 и View 2 будет пробел. Поскольку текст в TextView увеличивается дольше, TextView должен расти, нажав View 1 вправо, пока не останется больше пробелов. Затем нужно эллипсизовать, разрезать текст в TextView и добавить в конце многоточие ( "..." ).
Итак, результат должен выглядеть примерно так:
+----------------------------------------+
| short text [view1] [view2] |
+----------------------------------------+
| long text with ell ... [view1] [view2] |
+----------------------------------------+
Я пробовал:
- TableLayouts, но они, похоже, очень медленно прокручиваются на некоторых устройствах.
- RelativeLayouts, но у меня либо были перекрывающиеся представления, либо view1 или view2 полностью исчезли.
- GridLayouts, но TextView всегда растет до тех пор, пока он не займет всю ширину экрана, таким образом нажав view1 и view2 на экран.
Это GridLayout, который я пробовал:
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_gravity="left|fill_horizontal"
android:ellipsize="end"
android:singleLine="true"
android:text="Long text to demonstrate problem with TextView in GridLayout taking up too much space despite ellipsis" />
<TextView
android:layout_gravity="left"
android:text="(view1)" />
<TextView
android:layout_gravity="right"
android:text="(view2)" />
</GridLayout>
View 1 и View 2 на самом деле не являются TextViews, я просто использовал их в этом примере для упрощения.
Есть ли способ достичь этого, не используя TableLayouts?
EDIT: По просьбе, вот моя попытка решить это с помощью RelativeLayout. TextView обрабатывает всю ширину экрана в этом случае, поэтому не видны view1 или view2.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/rl0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:ellipsize="end"
android:singleLine="true"
android:text="Long text to demonstrate problem with TextView in GridLayout taking up too much space despite ellipsis" />
<TextView
android:id="@+id/rl1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/rl0"
android:layout_marginLeft="10dp"
android:text="(view1)" />
<TextView
android:id="@+id/rl2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/rl1"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dp"
android:text="(view2)" />
</RelativeLayout>