Too much padding around Button's Text

padding css
squarespace button padding
container padding
css button padding
vertical padding
css font padding

I have a fragment that takes up the whole screen, with Buttons and a SeekBar which scale to fit it, as well as fixed size TextViews. I use linear horizontal and vertical layouts with weights to achieve this.

The problem is I can't get the button text large enough without it making the buttons expand in size. For some reason, any text size greater than about 35sp makes the button expand, no matter how big the button is. This screen shot shows the button sizes have plenty of space for the text:

Ideally I would like the "<" and ">" characters to fill the buttons. (I was going to programmatically change the font size according to the button size, e.g. for different screen sizes) but haven't tried since I can't even get the static layout to work.

Edit: I would like to avoid images, since if I had 15 buttons, and 8 buckets, that would be 120 images I need!

<LinearLayout xmlns:android=""
    android:paddingTop="0dp" >

    <!-- ........ -->

        android:textAppearance="?android:attr/textAppearanceLarge" />

        android:layout_weight="2" >

            android:textSize="35sp" />

            android:textSize="35sp" />


        android:layout_weight="1" />

    <!-- ........ -->


I have tried adding the following line to Buttons, but it only makes a small difference, if any:


Advice on getting the font height to fill the buttons without padding is my primary question. (But if the problem of dynamically sizing the text to fill the buttons for different screen sizes can be solved at the same time, that would be brilliant).

Edit: it turns out that using larger font sizes affects the effect of weighting for the height of the linear layouts, which is why there seemed to be padding - larger font size increased the button size, not because of the padding (which was 0) but because of the weighting

Button is not the right widget for your purpose. Use an ImageButton (or even an ImageView) instead.

I was going to programmatically change the font size according to the button size, e.g. for different screen sizes

Your current approach will land you in a lot of problems regarding proper sizing of your UI components. Given the plethora of android devices out there, screen size is just one aspect of the problem. You will also be dealing with varying screen densities. Best approach would be to put size/density buckets (drawable-mdpi/hdpi/xhdpi) to use. Help android in working for you.

Use drawables to indicate next and previous. If you're worried about the drawables being too small for tablet screens, create appropriate drawable resources/folders:

// Phones - 4 to 7 in

// Tablets - 7 to 10 in

// Tablets - 10 in

This list may not be exhaustive. Consider doing some research before finalizing your size/density buckets.


@ drawable size 32dp:

@ drawable size 64dp

Now it becomes quite straightforward - finalize drawable size by visual inspection on a phone, on a 7 inch tablet, and on a 10 inch tablet. Then use density scales to create and store appropriately sized drawable in the folders I mentioned above. Let android deal with what bucket to pick from.

Unwanted padding around buttons. CSS, So what I intended to do was to define a div, centred in a black background. Within this div would be my board. Since 8 cells are needed  I'm fussing about with a GUI and find the JButton objects require way too much padding before they decide to display my button text in the desired font size. If anyone here knows how to reduce the blank spacing along the button sides to make more room for text?

The problem is by default buttons include a minHeight attribute. I had the same problem and solved it with just a single line of code in my XML file:


How can I reduce space between "buttons"?, I have used the below code here ( along with some extra code to give a fixed width and also increase the default font size. I  A button with the word "kit" on it takes up this space: -kit- which is really not too bad. A button with the word Hi takes up only as much space as the text with only tiny padding at each end. A button with the word "scooby doo" on it will take up this space: ----scooby doo---- A button with text like "scooby doo's treats" becomes:

There is a quick and easy solution to your problem! Auto-sizing text in Android is fiendishly difficult in my experience, especially when padding is involved. I would advise that instead of using an angle bracket character, you use a drawable - there are plenty of arrow icons available online - and an ImageButton. For example:

        android:textSize="35sp" />

By using different ScaleTypes you can alter the stretching of the image. Even better, the screen sizes problem is solved because you can add different drawables for different densities.

How to manipulate elements using margin and padding – Splash , Margin controls the space around an element while padding controls the Margin controls how far away the button is from other elements. it is recommended to use equal vertical margins so that spacing is predictable. Set padding attribute on Button in android Set padding left,top,right,bottom,start,end in button. With the use of padding attribute developer can set button name text alignment above the button and set button text location. After setting up padding attribute in button tag button will automatically stretch out as defined padding attribute size.

Use minWidth="0" or "1" to reduce the horizontal padding on a text Button.

CSS padding-bottom Property, More "Try it Yourself" examples below. Definition and Usage. An element's padding is the space between its content and its border. The padding-bottom property  The blue represents the content in that specific cell, and the white space around it indicates the padding in pixels between the content and edge of the cell. Since <cellpadding> is an HTML attribute, it can’t be overridden with a CSS media query to optimize for mobile.

Remove blank spaces between buttons in HTML, CSS, How do I reduce the space between two buttons in HTML? The CSS padding properties are used to generate space around an element's content, inside of any defined borders. With CSS, you have full control over the padding. There are properties for setting the padding for each side of an element (top, right, bottom, and left).

padding, of the element's content, inside any defined border. Every element on a web page is rectangular. padding there is around that text in the button, thus making the button itself much to wide, and wasting too much space on the page.

padding-bottom, How do you add padding to an image in HTML? If you use the Wide layout, the Page Content Padding option will control how much padding there is above and below your body content (under the Header and the Page Title Bar and above the Footer). Finally, if you use the 100% Width page template, there is a setting called 100% Width Padding to specify how much left and right padding there will be on content that goes full width.

  • Thank you - I was hoping to avoid this, as this means creating a LOT of images. In my app I have about 15 icons, so if I want 8 buckets, that's 120 images! I am utterly shocked with Google for this. It seems really poor. I don't suppose you know why Google essentially turned their back on SVG in favour of bitmaps?
  • Say I have a font.ttf file that has all the icons I need, is there a quick way of exploding it into the various drawables? Either at compile time, pre-compile time, or even runtime?
  • @Jodes I had similar questions when I first started dabbling with Android. Unfortunately, this is a necessary evil. There's a very informative post on use of SVGs on mobile platform here: link. The author discusses the topic in quite some detail. During my research, I also found some performance-related problems with the use of SVGs. Dianne mentions some of these issues here.
  • @Jodes On an app I am working on, my drawable folders currently hold a total of 1100 files. This number will of course go down as the project nears completion. Any way, the closest thing to SVGs that android supports natively is the family of xml drawables: ShapeDrawables, LayerDrawables etc. These drawables are defined in xml and placed in the res/drawable folder - they need not be placed in more than one density bucket if you define their size in dp(density-pixels). So, no drawable-ldpi/-mdpi/-hdpi/-xhdpi/-etc.`.
  • @Jodes Mind you, xml drawables will have to be defined with appropriate size changes and placed in drawable-large/-xlarge folders. But there is a way to circumvent this - define values/dimens.xml, values-large/dimens.xml and values-xlarge/dimens.xml and add a new dimension to each of these files, say drawable_width. Now, you are free to assign a value to drawable_width - example - 16dp in case of values/dimens.xml, 24dp for values-large/dimens.xml, and 32dp for values-xlarge/dimens.xml - android will choose the appropriate size based on device.