Adam R. Turner
Adam R. Turner

Reputation: 139

Why are my textviews disappearing inside my ConstraintLayout with guidelines?

This is my first time trying to use Guidelines within a ConstraintLayout, so maybe I'm missing something? I've tried adding padding to all of the elements internal to the ConstraintLayout. Should I just abandon the ConstraintLayout and use a couple of Relative Layouts? The textviews are linked to the buttons and the guidelines within the CosntraintLayout, which is itself inside a LinearLayout as you can see below.

<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="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#ffffff"
android:gravity="center_horizontal"
android:orientation="vertical">


<include layout="@layout/toolbar" />

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guidelineLeft"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_begin="16dp" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guidelineHorizontal1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_begin="18dp" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guidelineHorizontal2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_begin="72dp" />

    <TextView
        android:id="@+id/txt_install_suggestion"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:fontFamily="sans-serif-black"
        android:textSize="14dp"
        android:padding="1px"
        app:layout_constraintStart_toStartOf="@+id/guidelineLeft"
        app:layout_constraintTop_toBottomOf="@+id/guidelineHorizontal1"
        tools:text="@string/invite_pal_to_install" />

    <Button
        android:id="@+id/btn_suggestInstall"
        style="@style/AppTheme.Button"
        android:layout_width="42sp"
        android:layout_height="42sp"
        android:layout_marginStart="12dp"
        android:padding="1px"
        android:layout_marginTop="8dp"
        android:text="@string/fa_paper_plane"
        app:layout_constraintStart_toEndOf="@+id/txt_install_suggestion"
        app:layout_constraintTop_toBottomOf="@+id/guidelineHorizontal1" />


    <TextView
        android:id="@+id/txt_invite_pal_suggestion"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:fontFamily="@font/copse"
        android:textSize="14dp"
        android:padding="1px"
        android:typeface="normal"
        app:layout_constraintStart_toStartOf="@+id/guidelineLeft"
        app:layout_constraintTop_toBottomOf="@+id/guidelineHorizontal2"
        tools:text="@string/invite_pal_to_project" />

    <Button
        android:id="@+id/btn_suggestInvitePal"
        style="@style/AppTheme.Button"
        android:layout_width="42sp"
        android:layout_height="42sp"
        android:padding="1px"
        android:layout_marginStart="118dp"
        android:layout_marginTop="8dp"
        android:text="@string/fa_paper_plane"
        app:layout_constraintStart_toEndOf="@+id/txt_invite_pal_suggestion"
        app:layout_constraintTop_toBottomOf="@+id/guidelineHorizontal2" />

</androidx.constraintlayout.widget.ConstraintLayout>

Image of what this xml should render

Upvotes: 0

Views: 632

Answers (2)

Uuu Uuu
Uuu Uuu

Reputation: 1282

tools:text only show text for the layout preview only. You have to use android:text attribute instead of tools:text in your TextView

Upvotes: 2

user13043137
user13043137

Reputation:

You can set the top-level layout as constraintlayout

not LinearLayout

Upvotes: 0

Related Questions