Reputation: 481
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.
Upvotes: 1
Views: 368
Reputation: 1724
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
).
Upvotes: 2
Reputation: 769
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>
Upvotes: 0