views:

2285

answers:

1

Hi,

I am trying to set padding in shape declared in XML file. But whatever I set, nothing changes related to padding. If I modify any other properties, I see updated UI. But it doesn't work with padding. Could you please advice possible reasons for this?

I will provide below example of my shape.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <stroke android:width="1dp" android:color="#ffffff" android:dashWidth="2dp"/>
    <solid android:color="@color/button_white_cover" />
    <corners android:radius="11dp" />
    <padding android:left="1dp" android:top="20dp"
      android:right="20dp" android:bottom="2dp" />
</shape>

Thanks

+2  A: 

Hi,

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"&gt;
   <item android:drawable="@drawable/shape_below"/>
   <item android:top="10px" android:right="10px" android:drawable="@drawable/shape_cover"/>
</layer-list>

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

Thanks.

Lyubomyr Dutko
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