'how to make a TextView strech across the screen, filling it up?

<?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/pleaseChooseText"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:gravity="center"
        android:textAlignment="center"
        android:text="Please Choose your Mood"
        android:textColor="@color/black"
        android:textStyle="bold"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

I want to make this text fill up screen width but not the screen height, would this work here or programatically, how do I do that?



Solution 1:[1]

use this

<TextView
android:id="@+id/pleaseChooseText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Please Choose your Mood"
android:textColor="@color/white"
android:textStyle="bold"
android:layout_marginTop="60dp"
android:layout_marginBottom="15dp"
/>

Solution 2:[2]

    <?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/pleaseChooseText"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:gravity="center"
        android:textAlignment="center"
        android:text="Please Choose your Mood"
        android:textColor="@color/black"
        android:textStyle="bold"
        app:layout_constraintTop_toTopOf="parent"
        tools:layout_editor_absoluteX="5dp" />
</androidx.constraintlayout.widget.ConstraintLayout>

The important properties are:

android:layout_height="match_parent"
android:layout_width="match_parent

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Wahdat Jan
Solution 2 Dankyi Anno Kwaku