Проблема совместного расположения двух TextView при большом объеме текста

Рейтинг: 0Ответов: 1Опубликовано: 28.02.2023

Есть горизонтальный 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>

Ответы

▲ 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>