1

I have a button and even though the text is centered on the layout preview, when I run the application it slides down. Any idea of what may be happening.

Button XML

<Button
    android:id="@+id/increment_setup_activity"
    android:layout_width="131dp"
    android:layout_height="59dp"
    android:background="@drawable/settings_panel"
    android:text="+"
    android:gravity="center"
    android:textColor="@color/soft_color"
    android:textSize="50sp"
    android:layout_marginTop="8dp"
    app:layout_constraintTop_toBottomOf="@+id/constraintLayout3"
    android:layout_marginRight="0dp"
    app:layout_constraintRight_toRightOf="@+id/

Android Studio Layout Preview

Android studio layout preview

Running on my phone

Mobile output

caiomcg
  • 501
  • 10
  • 23
  • did the searching for you http://stackoverflow.com/a/10978706/4944007 – Ismail Iqbal Mar 24 '17 at 19:20
  • 1
    try reducing the font size and see if it is centered – Ismail Iqbal Mar 24 '17 at 19:20
  • This is indeed the problem, I saw this post and I did alter the text before posting this question but it was still not centered. After finding the link to the post again - this time by you - I decided to make a more extreme reduction and it works fine. I am not sure if I should flag my question or leave it here. Nevertheless a big thanks and an upvote to you. – caiomcg Mar 25 '17 at 15:44
  • caiomcg I'll add an answer please accept it – Ismail Iqbal Mar 25 '17 at 15:57

2 Answers2

1

Since you have a larger font size center align text (by default on a button) does not work try reducing the font size more info visit this stackoverflow answer

Community
  • 1
  • 1
Ismail Iqbal
  • 2,774
  • 1
  • 25
  • 46
-1

add it's:

  <LinearLayout android:layout_width="match_parent" 
                  android:id="@+id/linearLayout1"  
                  android:gravity="center"
                  >

add your component here and button

</LinearLayout>