androidbuttonuitextposition

Android Button text positioning


How can I make the text appear NEXT to a button, instead of being ON the button?

Here is a screenshot of what i need:

enter image description here

You can see the text on the first button. It is written ON the button, and I couldn't move it from it (aside from changing the gravity, but it's not really what I am after). Next to a second button, I put a label, as a guideline of something I would like to achieve.

Is there a way of doing this in Android? it is pretty straightforward in ObjectiveC.


Solution

  • You can use a TextView instead of a button.
    TextViews are clickable, the very same way as buttons are.

    And the listeners are assigned in the same way as you would do with buttons.
    So, very small changes in code are needed (renaming your controls prefixes and changing type from Button to TextView, which is really a trivial task).

    You can add a drawable to it, by specifying the attribute android:dawableLeft="@drawable/my_icon", for a left side graphics

    You can use drawableLeft and/or drawableRigth and/or drawableTop and/or drawableBottom.
    You can specify drawablePadding, to add some space between the graphics and the text

    This is a best practice, in keeping your design hyerarchy as flatten as possible.

    Note that you are not limited to images... you can use xml drawables too!