CJR
CJR

Reputation: 3572

TextView not starting at left

Here's a picture to help me explain my problem:

The black box is the whole screen. The red box is the TextView. The green is the text. When I run my code, it looks like the left screen, but I want to it look as it does on the right. (start from left)

enter image description here

Here is the TextView code:

<TextView
    android:id="@+id/info_ruta"
    android:layout_width="256dp"
    android:layout_height="80dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:text="@string/info_sumary"
    android:textColor="#FFF"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/day_seven_id" />

When trying to add android:gravity="left" or ="start" it does not help with my problem. What am I missing here?

Upvotes: 1

Views: 249

Answers (2)

Silo&#233; Bezerra Bispo
Silo&#233; Bezerra Bispo

Reputation: 2244

Use android:layout_width="match_parent" and android:gravity="left" on attributes of XML.

The match_parent is fundamental for this.

Upvotes: 2

Pavneet_Singh
Pavneet_Singh

Reputation: 37404

use android:layout_width="match_parent" instead of fixed width android:layout_height="80dp" so it would be

<TextView
    android:id="@+id/info_ruta"

    android:layout_width="match_parent"                             

    android:layout_height="80dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:text="@string/info_sumary"
    android:textColor="#FFF"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/day_seven_id" />

match_parent with android:width mean cover the complete width which is occupied by the parent container.

Upvotes: 2

Related Questions