0

I designed coloured Android Button Drawables and put them in a TableLayout. The problem is that Android's default buttons do not take up the entire cell space, but my drawables do (See attatched pictures). How can I adjust my XML so that my drawables leave a bit of space like the default buttons? I've pasted the XML code at the bottom.

Custom Buttons:

Custom buttons taking all available cell space

Default Buttons:

Default buttons leave gaps

XML CODE:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true"><shape>
            <gradient android:angle="90" android:endColor="@color/dark_red" android:startColor="@color/brick_red" />

            <corners android:radius="10dip" />

            <padding android:bottom="10dip" android:left="10dip" android:right="10dip" android:top="10dip"></padding>

        </shape></item>
    <item android:state_focused="true"><shape>
            <gradient android:angle="270" android:endColor="@color/dark_red" android:startColor="@color/brick_red" />

            <corners android:radius="10dip" />

            <padding android:bottom="10dip" android:left="10dip" android:right="10dip" android:top="10dip" />
        </shape></item>
    <item><shape>
            <gradient android:angle="270" android:endColor="@color/dark_red" android:startColor="@color/red" />

            <corners android:radius="10dip" />

            <padding android:bottom="5dip" android:left="5dip" android:right="5dip" android:top="5dip" />
        </shape></item>

</selector>

Thanks for your help :)

W.K.S
  • 9,787
  • 15
  • 75
  • 122

1 Answers1

1

Did you try to use the Top, Left, Bottom and Right attributes of items ? See : How to add padding to gradient <shape> in Android?

Alternatively, in your final layout that uses the button, you could use the attribute : android:layout_margin(Right,Left,Top,Bottom)

Community
  • 1
  • 1
Yahel
  • 8,522
  • 2
  • 24
  • 32
  • That layout_margin did the trick. Is it possible to set the margin of the button within the Button's XML itself? I looked through the intellisense list of available settings, and I couldn't find it. – W.K.S Jan 27 '12 at 14:36
  • if you are thinking the selector xml, you would have to try to the android:top, android:left, android:bottom and android:right in the items tag of your selector xml. Or to make it cleaner, but with the overhead of creating a new file, create a button_with_padding.xml, add just one item referencing the xml you already have as the drawable and set the top, left, right, bottom value there. – Yahel Jan 27 '12 at 16:50