How to fix ConstraintLayout TextView overlaps when more than two lines

I had a problem with layout constraints, where the text in one text view falling into the second line will not push another text view, which is bounded under it, to the middle of the line.

I built a simple layout with three text views. The first text view is located on the left and has a typing width. The second sits to his right, between him and his parent. The third sits below the second and to the left of the first.

I want it to look like this: An action layout with three text views as desired

However, if I delete the text "Do not overlap." I got: An action layout with a third text view overlapping the second.

The point at which it changes ("O" in "Do not overlap") appears when the length of the text fills two lines, when the first text view is missing: Image showing that the first TextView was not there so that the text would look great.

, , , Text View 3, ? , .

XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context="com.testapp.myapplication.MainActivity">

    <TextView
        android:id="@+id/text_view_1"
        android:layout_width="120dp"
        android:layout_height="0dp"
        android:background="@color/colorAccent"
        android:text="Text View 1"
        android:textAppearance="@style/TextAppearance.AppCompat.Body2"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/text_view_2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="#22AA99"
        android:text="Text View 2 Showing problem with overlap. Overlapping. Not O"
        android:textAppearance="@style/TextAppearance.AppCompat.Body2"
        app:layout_constraintLeft_toRightOf="@id/text_view_1"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/text_view_3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#FF00FF"
        android:text="Text View 3"
        android:textAppearance="@style/TextAppearance.AppCompat.Body2"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toRightOf="@id/text_view_1"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/text_view_2" />

</android.support.constraint.ConstraintLayout>

.

+1
2

app:layout_constrainedHeight="true"

1.1.0-beta2, wrap_content. , , app:layout_constraintBottom_toBottomOf="parent", .

+1

:

app:layout_constraintBottom_toBottomOf="parent"

TextView text_view_3 :

<TextView
    android:id="@+id/text_view_3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#FF00FF"
    android:text="Text View 3"
    android:textAppearance="@style/TextAppearance.AppCompat.Body2"
    app:layout_constraintLeft_toRightOf="@id/text_view_1"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@id/text_view_2" />
+3

Source: https://habr.com/ru/post/1696297/


All Articles