Search code examples
androidandroid-constraintlayout

Why I can't apply margin for textView (android)?


TextView code:

<TextView
    android:id="@+id/description_text_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginEnd="16dp"
    android:text=""
    android:textSize="20sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/domain_text"
    tools:text="Description"
    tools:visibility="visible" />

Here you can look at whole XML file Everything seems to be correct but if I launch the app I see that it doen't work. Look at the screenshot. image

If you don't understand something, write about it, my english is quite poor.
How can I fix my problem?


Solution

  • When you use constraints and want to set the width/height of the widget according to the set constraints, you set its width/height to 0dp which means fill the contraints as:

    android:layout_width="0dp"
    android:layout_height="0dp"
    

    It will fill all the available space according to the Constraints and then, will your margin work.