views:

83

answers:

1

Looking at the following image, the button on the left is android 2.1, the one on the right is 2.2:

alt text

As you can see the corners on the left image are not being applied correctly, but they look perfect in 2.2. The xml I'm using is here:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"&gt;
<item android:right="0dip" android:left="0dip" android:bottom="0dip"
    android:top="0dip">
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <corners android:bottomRightRadius="3dip"
            android:bottomLeftRadius="3dip" android:topLeftRadius="3dip"
            android:topRightRadius="3dip" />
        <stroke android:width="1dip" android:color="#70532B" />
        <padding android:left="1dip" android:top="1dip"
            android:right="1dip" android:bottom="1dip" />
    </shape>
</item>
<item android:right="0dip" android:left="0dip" android:bottom="0dip"
    android:top="9dip">
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <gradient android:startColor="#ECAF08" android:endColor="#F6E34B"
            android:angle="270" />
        <corners android:bottomRightRadius="3dip"
            android:bottomLeftRadius="3dip" android:topLeftRadius="0dip"
            android:topRightRadius="0dip" />

    </shape>



</item>
<item android:right="0dip" android:left="0dip" android:bottom="11dip"
    android:top="0dip">
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <gradient android:startColor="#FCEF94" android:endColor="#FFBA00"
            android:angle="270" />
        <corners android:bottomRightRadius="0dip"
            android:bottomLeftRadius="0dip" android:topLeftRadius="3dip"
            android:topRightRadius="3dip" />
    </shape>
</item>

am i doing something wrong, or is this a bug in android 2.1???

+1  A: 

Clever way to make a gradient button.

I wonder if this is related to the <corners> xml being buggy in Android 2.1 and below. bottomLeftRadius actually corresponds to bottomRightRadius, and vice versa. They may have fixed it in 2.2, thus it looks correct in 2.2, but you're overlapping in unexpected ways in 2.1 and lower. If that's the case, you can use version-targeted folders to use a different drawable for each version (aka, /drawable-v7/ and /drawable-v8/).

Daniel Lew
so the issue is that it seems like you can't have a rectangle with the top cornered and the bottom not cornered. i've seen the issue before. the last time i ran into it, i found a work around by basically overlaying a rectangle on the top part of the cornered rectangle, thus exposing the bottom part as cornered and leaving the top as flat. it was hacky but it worked.
Ben
Ben