Reputation: 261
I Try to center a drawable bitmap within a shape with padding, using layer-list. But i can't get padding around the image. THis is not working:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:angle="270"
android:centerColor="#ffffffff"
android:endColor="#ffbab8b9"
android:startColor="#ffcfccce" />
<stroke
android:width="1px"
android:color="#A0A0A0" />
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
</shape>
</item>
<item
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp">
<bitmap android:src="@drawable/logo"
android:gravity="center" />
</item>
</layer-list>
Does someone have an idea how to center a bitmap (for scaling) with padding?
Right now the bottom,left,... parameters are just ignored. The bitmap is scaled 100% within the Button.
I need it for a Button and can't use an ImageButton here. Also the Button don't have text in that special case, so compoundDrawable will also not work. I need to do it with a Button.
Best regards, Juergen
Upvotes: 1
Views: 2503
Reputation: 4477
You can put icon straight in item element, like this:
<item
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp"
android:drawable="@drawable/logo"
android:gravity="center"/>
Upvotes: 0
Reputation: 261
Ok, looks like theres no way using padding of a bitmap within layer-list. I just decreased the bitmap size and now it fits in the button perfectly. But i don't know if it is looking same sized on every device...
Upvotes: 1