Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alignment of text on button

I am creating a custom button. I want to set the position of text on button.

  • I have two background images for button (button_off and button_on) first is for normal button and second is for onFocus / onPressed state.

enter image description hereenter image description here

  • Now I have to put text on button then it should look like:

enter image description hereenter image description here

But i am unable to set the exact position of the text on this background button image. Please share your suggestion to solve this issue.

like image 782
Saurabh Pareek Avatar asked Mar 11 '11 12:03

Saurabh Pareek


3 Answers

You can try using 9-patch image as a background. More information on this here: http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch

like image 65
sergeytch Avatar answered Sep 27 '22 03:09

sergeytch


You can set these properties in XML file, `

<Button
    android:id="@+id/button1"
    android:layout_width="120dp"
    android:layout_height="wrap_content"
    android:drawablePadding="5dp"
    android:drawableLeft="@android:drawable/ic_lock_lock"
    android:text="All" 
    android:gravity="center"/>

`

like image 31
habib ullah Avatar answered Sep 26 '22 03:09

habib ullah


Align the text , use gravity option ! or try with padding

like image 32
sat Avatar answered Sep 27 '22 03:09

sat