0

Есть горизонтальный LinearLayout в котором расположены 2 textView. Проблема следующая: если в первом textView большой объем текста, то он полностью перекрывает второй textView как бы выталкивая его в невидимую область , несмотря на то, что в последнем тоже есть текст. Мне нужно чтобы часть текста в первом textView была скрыта (использовал атрибуты maxLines и ellipsize), когда текст слишком велик, но при этом нужно чтобы текст второго textView тоже был виден.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:maxLines="1"
        android:ellipsize="end"
        tools:text="@tools:sample/lorem/random"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:maxLines="1"
        tools:text="random text"/>


</LinearLayout>
2
  • Выставьте "вес" каждому TextView. developer.android.com/develop/ui/views/layout/linear#Weight 28 фев 2023 в 20:19
  • К сожалению, не мой случай. Текст во втором виджете должен идти сразу после предыдущего, то есть между ними не должно быть отступа. С "весами" этого не достичь.
    – Vladimir
    28 фев 2023 в 20:31

1 ответ 1

0

В общем решение выглядит так:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:maxLines="1"
        android:ellipsize="end"
        android:layout_weight="1"
        tools:text="@tools:sample/lorem/random"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:maxLines="1"
        android:layout_weight="0"
        tools:text="random text"/>
</LinearLayout>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.