Правильный перенос текста ConstraintLayout

У меня есть вот такой код:

<android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/titlelayout"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/text1"
            android:text="text1"
            android:textColor="@color/yellowcardcolor"
            android:singleLine="true"
            android:autoSizeTextType="uniform"
            android:paddingBottom="@dimen/doublemenuhalflrpaddings"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintRight_toLeftOf="@id/text2"
            app:layout_constraintBottom_toBottomOf="parent"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/text2"
            android:text="d sd fasddkddda d d d d asdddddd asdf f asd ads fasdf asd fsaf as dfasdf asdf asd fasd fasd fasd fasd ff asddddf asdf d d d d d ddddddddhgв "
            android:autoSizeTextType="uniform"
            android:textColor="@color/colorblack"
            android:paddingHorizontal="@dimen/doublemenuhalftbpaddings"
            android:paddingBottom="@dimen/doublemenuhalflrpaddings"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toEndOf="@id/text1"
            app:layout_constraintRight_toLeftOf="@id/text3"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/text3"
            android:text="text3"
            android:autoSizeTextType="uniform"
            android:textColor="@color/yellowcardcolor"
            android:singleLine="true"
            android:paddingBottom="@dimen/doublemenuhalflrpaddings"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintLeft_toRightOf="@id/text2"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"/>

    </android.support.constraint.ConstraintLayout>

Мне нужно, чтобы text1 был закреплен строго в начале экрана, text3 строго в конце, а text2 был слева от text1 и переносился на следующую строку (не налегая при этом поверх text3), когда его длина больше, чем место между text1 и text3. Как это сделать?


Ответы (2 шт):

Автор решения: Andrew

Можно использовать LinearLayout с весом у каждого элемента:

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="21"
android:orientation="horizontal" >

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/text1"
            android:text="text1"
            android:layout_weight="7"
            android:textColor="@color/yellowcardcolor"
            android:singleLine="true"
            android:autoSizeTextType="uniform"
            android:paddingBottom="@dimen/doublemenuhalflrpaddings"/>

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/text2"
            android:text="d sd fasddkddda d d d d asdddddd asdf f asd ads fasdf asd fsaf as dfasdf asdf asd fasd fasd fasd fasd ff asddddf asdf d d d d d ddddddddhgв "
            android:autoSizeTextType="uniform"
            android:textColor="@color/colorblack"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_weight="7"
            android:paddingHorizontal="@dimen/doublemenuhalftbpaddings"
            android:paddingBottom="@dimen/doublemenuhalflrpaddings"/>

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/text3"
            android:text="text3"
            android:layout_weight="7"
            android:autoSizeTextType="uniform"
            android:textColor="@color/yellowcardcolor"
            android:singleLine="true"
            android:paddingBottom="@dimen/doublemenuhalflrpaddings"/>
    </LinearLayout>

это самый простой вариант как мне кажется. Можно конечно заморочиться и сделать все в constraintLayout :) но в моем варианте все будет строго фиксировано.

→ Ссылка
Автор решения: alexbayker
<android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/titlelayout"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/text1"
            android:text="text1"
            android:textColor="@color/yellowcardcolor"
            android:singleLine="true"
            android:autoSizeTextType="uniform"
            android:paddingBottom="@dimen/doublemenuhalflrpaddings"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toStartOf="@id/text2"
            app:layout_constraintBottom_toBottomOf="parent"/>

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/text2"
            android:text="d sd fasddkddda d d d d asdddddd asdf f asd ads fasdf asd fsaf as dfasdf asdf asd fasd fasd fasd fasd ff asddddf asdf d d d d d ddddddddhgв "
            android:autoSizeTextType="uniform"
            android:textColor="@color/colorblack"
            android:paddingHorizontal="@dimen/doublemenuhalftbpaddings"
            android:paddingBottom="@dimen/doublemenuhalflrpaddings"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toEndOf="@id/text1"
            app:layout_constraintEnd_toStartOf="@id/text3"
            app:layout_constraintBottom_toBottomOf="parent"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/text3"
            android:text="text3"
            android:autoSizeTextType="uniform"
            android:textAlignment="viewEnd"
            android:textColor="@color/yellowcardcolor"
            android:singleLine="true"
            android:paddingBottom="@dimen/doublemenuhalflrpaddings"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toEndOf="@id/text2"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"/>

    </android.support.constraint.ConstraintLayout>
→ Ссылка