Brijesh Chandrakar Brijesh Chandrakar - 20 days ago 5
Android Question

How to adjust android button text at centre without padding?

I searched for the solution. It can be done with paddingLeft and paddingRight set to equal values. However, the problem with this is it doesn't work well for different screens. Here is my button code.

<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/sign_in_orange"
android:background="@drawable/orange_button"
android:text="Continue"
android:textSize="15sp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_marginRight="7dp"
android:minHeight="35dp"
/>


The orange_button drawable is just used to attribute round edges to the button. My ultimate goal is to have a button with text centered and positioning almost same in different screens. Note that I have used linear layout in the parent xml.

Answer

You can use

            android:gravity="center"