Search code examples
androidxmlandroid-layout

textAlignment wont work with supportsRtl false


I have created buttons that look as follows:

enter image description here

The xml code for it is:

<androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_marginTop="8dp">
            <Button
                android:id="@+id/btn_whishlist"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_marginStart="24dp"
                android:layout_marginRight="24dp"
                android:drawableLeft="@drawable/btn_whishlist"
                android:text="Whishlist"
                android:textColor="@color/colorGray"
                android:textAlignment="textStart"
                android:textAllCaps="false"
                android:background="@android:color/transparent"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toStartOf="@+id/tvWhishlistBooksCount"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.0" />

            <TextView
                android:id="@+id/tvWhishlistBooksCount"
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:gravity="center"
                android:textSize="16dp"
                android:text="0"
                app:layout_constraintEnd_toEndOf="parent"
                android:layout_marginEnd="24dp"
                app:layout_constraintStart_toEndOf="@+id/btn_whishlist"
                app:layout_constraintTop_toTopOf="@+id/btn_whishlist" />

        </androidx.constraintlayout.widget.ConstraintLayout>

Everything worked great however for some reason the text inside the button stopped appearing at the start and it always shows it in the middle.

Is there any way to fix it so It will appear again next to the heart shape/message icon?

EDIT:

I found that when I change my manifest to android:supportsRtl="true" it works. However, I do want it to be android:supportsRtl="false" so I need to overcome it somehow.

Thank you.


Solution

  • try this :

         <Button
            android:id="@+id/btn_whishlist"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_marginStart="24dp"
            android:layout_marginRight="24dp"
            android:drawableLeft="@drawable/btn_whishlist"
            android:text="Whishlist"
            android:textColor="@color/colorGray"
            android:textAlignment="textStart" \\ remove this line 
            android:gravity="start"            \\ add this line
            android:textAllCaps="false"
            android:background="@android:color/transparent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/tvWhishlistBooksCount"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.0" />