blood73
blood73

Reputation: 59

ConstraintLayout and 2 TextViews on one line

I have a ConstraintLayout with 2 TextViews on one line. Like this:

enter image description here

It's good with small header and text. But on some situations I have this:

What I can do with this?

Code:

<androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/regionLimitationsLayout"
        android:layout_marginTop="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Very very very very big header"
                android:textColor="@color/black"
                android:textSize="14sp"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintTop_toTopOf="parent"/>

        <TextView
                android:id="@+id/regionLimitationsTextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                tools:text="TEST TEST TEST TEST TEST TEST TEST"
                android:fontFamily="@font/roboto_medium"
                android:textColor="@color/black"
                android:textSize="14sp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

Upvotes: 1

Views: 1645

Answers (1)

Eugene Troyanskii
Eugene Troyanskii

Reputation: 892

Because of width wrap_content your textview bounds don't have a limit that's why they overlap each other when content to big. Here is what you have to do:

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/regionLimitationsLayout"
        android:layout_marginTop="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/tv1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="Very very very very big header"
            android:textColor="@color/black"
            android:textSize="14sp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/regionLimitationsTextView"
            app:layout_constraintTop_toTopOf="parent"/>

        <TextView
            android:id="@+id/regionLimitationsTextView"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            tools:text="TEST TEST TEST TEST TEST TEST TEST"
            android:fontFamily="@font/roboto_medium"
            android:textColor="@color/black"
            android:textSize="14sp"
            app:layout_constraintStart_toEndOf="@+id/tv1"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"/>

    </androidx.constraintlayout.widget.ConstraintLayout>

To learn more about how to use ConstraintLayout visit to official doc https://developer.android.com/reference/android/support/constraint/ConstraintLayout

Upvotes: 3

Related Questions