Reputation: 4831
I'm trying to have some margins inside a button between the text and the borders but I don't know how to specify them.
The only way I know is using android:layout_width="...", but this is not relative to the text size.
Thanks!
Upvotes: 34
Views: 60166
Reputation: 31483
To measure its dimensions, a view takes into account its padding. The padding is expressed in pixels for the left, top, right and bottom parts of the view. Padding can be used to offset the content of the view by a specific amount of pixels. For instance, a left padding of 2 will push the view's content by 2 pixels to the right of the left edge.
Read more at the official doc.
Upvotes: 0
Reputation: 33792
If you're looking for this kind of padding on the left and right of this cheeky text :
Here is what you do. :
<Button
android:id="@+id/she_was_good"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:soundEffectsEnabled="false"
android:layout_alignParentBottom="true"
android:paddingRight="25dp"
android:paddingLeft="25dp"
android:text="@string/im_sorry_lol_str" />
The part you are looking for is paddingRight
and paddingLeft
Upvotes: 112
Reputation: 4340
Use padding to add margin between border and text in button.
Upvotes: 39