8

i have bunch of buttons within linear layout. But there is spaces buttons. I set padding as 0 but there no change. There is someone who already had the same problem at http://www.mail-archive.com/android-developers@googlegroups.com/msg51104.html but no answer at there. Can you plese help me.

csfcse
  • 85
  • 1
  • 3

2 Answers2

19

Try to play with android:layout_margin attribute. For instance, to reduce space on the left/right side (assuming you have a horizontal set of buttons) you can do smth like this:

<Button
    android:layout_marginLeft="-3dip"
    android:layout_marginRight="-3dip"
    ... />
Vit Khudenko
  • 28,288
  • 10
  • 63
  • 91
  • Works for padding aswell on some layouts! – Magakahn Aug 27 '12 at 17:28
  • It's a shame that this is the best answer, not that it doesn't work, but a "guess and check" mechanism never seems to be the correct/most efficient method. Is this solution guaranteed to be portable? (ie will the `"-Xdip"` that works on one display work for all displays?) – Mike Nov 06 '13 at 19:45
  • 1
    @Mike Yes, you are right that this is actually a quick workaround. The best way would be to create a custom button drawable where you could control the border width. On the other hand as long as we use only dips across our layouts it should work pretty well on different screens. If this is used for native Android buttons, then there is definitely a risk Android will change buttons border in the future, so the "-Xdip" value will have to be adjusted. On the other hand that's what `targetSdk` in `AndroidManifest.xml` is for - to guarantee the expected behavior on future OSes. – Vit Khudenko Nov 07 '13 at 09:44
10

I'll refer you to a previous answer I gave on this:

If you're meaning you want them to be pushed to the edge, pixel for pixel, you'll need to use your own 9-patch for the button background, as the default one in Android has a few extra pixels around the border of its 9-patch background. For an example of this, look at the file in your SDK folder under:

platforms/android-8/data/res/drawable-hdpi/btn_default_transparent_normal.9.png

For example, this is what I get with the default:

alt text

And with a custom 9-patch I had made earlier:

alt text

Community
  • 1
  • 1
Kevin Coppock
  • 133,643
  • 45
  • 263
  • 274
  • Thank you. I add background color to my buttons and then spaces are gone. It was really help for me. – csfcse Dec 06 '10 at 15:06