Textview does not centralize on android 4.1.1

Asked

Viewed 61 times

1

I got a problem with mine layout, in API 16 ( 4.1.1 ) TextView is not centered. I am using ConstraintLayout.

The properties in XML are like this:

 <TextView
        android:id="@+id/txv_textomeio"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="8dp"
        android:fontFamily="sans-serif-condensed"
        android:text="@string/textoinicial"
        android:textAlignment="center"
        android:textAllCaps="false"
        android:textSize="24sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toTopOf="@+id/btn_iniciar"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/txv_certo"
        app:layout_constraintVertical_bias="0.503" />

como deveria ficar Como fica

  • @Danielgentil didn’t work

1 answer

1


Change the property layout_width for match_parent.

Instead of:

android:layout_width="wrap_content"
android:textAlignment="center"

Place:

android:layout_width="match_parent"
android:gravity="center"
  • Had already done so, unsuccessfully, remains aligned to the left

  • @Igoroliveira I took your same code and entered here and worked right with this change. xD

  • @Igoroliveira place also android:gravity="center"

  • Here is working with textAlignment and Gravity normally... Make sure your Textview is not inside a view that is wrap_content in width?

  • It is inside a constraintlayout with match_parent, I tried to do what you said, but without success too.

  • I will try to put inside a linear layout

  • The parent view should also be match_parent

  • Got it, I was editing xml v21, sorry for the glitch

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.