Husayn Hakeem
Husayn Hakeem

Reputation: 4590

Android: text not being centered inside button/textview with fixed width/height

I'm having an issue trying to do something really simple: Center text in a button/TextView that have a fixed width and height, my text keeps being pushed down as I increase its size, here's a sample of the code I'm using:

<Button
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:background="@drawable/circle_add_item"
            android:gravity="center"
            android:text="+"
            android:textColor="@color/green"
            android:textSize="75sp" />

Here's an image of what I'm getting as a result:

enter image description here

Would anyone give me a hand ?

Thanks !

Upvotes: 0

Views: 216

Answers (2)

Timofey Orischenko
Timofey Orischenko

Reputation: 1178

Also, you can use this way

<RelativeLayout
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:background="@drawable/circle">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="75sp"
        android:layout_marginTop="-20dp"
        android:background="@android:color/transparent"
        android:text="+"
        android:textColor="#00ff00"
        android:paddingTop="0dp"
        android:layout_centerVertical="true"/>

</RelativeLayout>

enter image description here

Upvotes: 1

Timofey Orischenko
Timofey Orischenko

Reputation: 1178

Try to add padding top as 0dp

    android:paddingTop="0dp"

Upvotes: 0

Related Questions