androidxmlandroid-layoutandroid-xml

TextViews don't show up in Android


In my Android app, I try to add a TextView to add titles to some of my Activities. However, it doesn't seem to work, since in none of my activities the TextViews don't show up. I'm new to developing Android apps, so I may be doing something fundamentally wrong, but I tried out to add different elements (Buttons, Plain Text, ...) and they all show up, I only have the Problem with my Textview.

Here's my code:

<androidx.constraintlayout.widget.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="match_parent"
    tools:context=".WishlistActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="173dp"
        android:layout_marginTop="87dp"
        android:layout_marginEnd="156dp"
        android:layout_marginBottom="625dp"
        android:text="Wishlist stuff"
        android:gravity="center_horizontal"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
    
    
</androidx.constraintlayout.widget.ConstraintLayout>```

Solution

  •     <?xml version="1.0" encoding="utf-8"?>
    
    <androidx.constraintlayout.widget.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="match_parent"
        tools:context=".MainActivity">
    
        <TextView
            android:id="@+id/textView"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_marginStart="173dp"
            android:layout_marginTop="87dp"
            android:layout_marginEnd="156dp"
            android:layout_marginBottom="625dp"
            android:text="Wishlist stuff"
            android:gravity="center_horizontal"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    
    
    </androidx.constraintlayout.widget.ConstraintLayout>
    

    Output image

    There is no error in code just correct the margin according to your screen size.