Take the 2-minute tour ×

I am trying to set padding in a <shape> declared within an XML file/layout. But whatever I set, nothing changes related to padding. If I modify any other properties, I see the effects on the UI. But it doesn't work with padding. Could you please advise on the possible reasons for which this might occur?

Here is the XML Shape I am trying to style:

    <stroke android:width="1dp" android:color="#ffffff" 

    <solid android:color="@color/button_white_cover" />

    <corners android:radius="11dp" />

    <padding android:left="1dp" 
             android:bottom="2dp" />
share|improve this question
add comment

2 Answers

up vote 20 down vote accepted

I have finally resolved my problem with padding.

So padding here will have no effect on the shape. Instead of this, you will have to apply padding in other drawable that will use it. So, I have a drawable that uses the shape and there I do following:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:drawable="@drawable/shape_below"/>
   <item android:top="10px" android:right="10px" android:drawable="@drawable/shape_cover"/>

So, as you can see in the second <item>-element I set padding (top and right). And after this everything works.


share|improve this answer
Hi, I don't understand how to apply this solution to the problem. I have a button that uses the shape and setting adnroid:top and android:right has no effect. How would I solve this? Thanks. –  icecream Oct 18 '10 at 7:08
I THINK what Lyubomyr is saying is to do something like this, which works for me, but then the corners always have an opaque white background, causing display issues (sorry for format in comments!): <layer-list xmlns:android="schemas.android.com/apk/res/android">; <item> <shape android:shape="rectangle"> <size android:width="0dp" android:height="45dp" android:color="@android:color/transparent" /> </shape> </item> <item android:top="0dp" android:right="0dp" android:bottom="0dp" android:left="0dp" android:drawable="@drawable/button_blue_shape" /> </layer-list> –  Dustin Feb 18 '11 at 22:12
Also off-topic but might be useful: if your drawable used is just a color, you can write like android:drawable="@color/divider" as well. BUT this breaks on older devices. I tested it on 2.2 and it was broken. Not sure at which level it became acceptable. –  Pius Jan 8 '13 at 8:48
add comment

The answer by Lyobomyr works, but here is the same solution applied but without the overhead of creating a new drawable, hence minimizing the file clutter :

How to add padding to gradient <shape> in Android?

share|improve this answer
add comment

Your Answer


