1

I have this drawable for my progressbar:

<item android:id="@android:id/background"  android:top="5dp">
    <shape>
        <gradient
            android:angle="270"
            android:centerColor="@color/gray11"
            android:centerY="0.75"
            android:endColor="@color/gray11"
            android:startColor="@color/gray11" />
    </shape>
</item>
<item android:id="@android:id/secondaryProgress"  android:top="5dp">
    <clip>
        <shape>
            <gradient
                android:angle="270"
                android:centerColor="@color/blue1"
                android:centerY="0.75"
                android:endColor="@color/blue1"
                android:startColor="@color/blue1" />
        </shape>
    </clip>
</item>
<item android:id="@android:id/progress" android:top="5dp">

    <clip>
        <shape>
            <gradient
                android:angle="270"
                android:endColor="@color/blue1"
                android:startColor="@color/blue1" />
        </shape>
    </clip>
</item>

I want to shift the drawable downwards so I added android:top="5dp" but the padding (downward shift) is not applied and I can't get why.

elfar
  • 461
  • 2
  • 6
  • 21

2 Answers2

2

This is probably way too late, but I am posting this here for anyone who has this problem in the future and stumbles upon this question.

Before Marshmallow, there was a bug where certain properties put on the children of a LayerDrawable were disregarded when that LayerDrawable was used as a progress drawable. The bug was actually in ProgressBar, where the value of android:progressDrawable would run through a tileify method, which would re-generate the LayerDrawable but would fail to copy certain properties (most notably the paddings).

You can see the fix for this in AOSP here.

The easiest workaround for this issue is to call setProgressDrawable from code instead of supplying android:progressDrawable. Because setProgressDrawable doesn't call tileify (and because tileify might as well be a no-op anyway for all cases where there is no BitmapDrawable), you'll keep your paddings and other properties.

Note, however, that if your progress drawable contains bitmap/BitmapDrawable, you may need to implement part of tileify yourself to make sure you're getting the same tiling behavior as from xml (or, on Lollipop and above, you can call setProgressDrawableTiled).

ahmedre
  • 1,684
  • 1
  • 14
  • 18
  • Thank you very much! Works perfectly! Remenber not put android:progressDrawable in xml because setProgressDrawable() not will have effect – Gilian Aug 30 '17 at 19:16
0

The padding property is not taken into account for < item > tag. It's simply not parsing or including it, since it makes little sense to do it there.

Properly set padding should be included as child in your < shape > tag like this:

<item android:id="@android:id/progress">
    <clip>
        <shape>
            <padding 
                android:top="5dp" />
            <gradient
                android:angle="270"
                android:endColor="@color/blue1"
                android:startColor="@color/blue1" />
        </shape>
    </clip>
</item>
Jitsu
  • 769
  • 3
  • 7